In signals of the form
the instantaneous frequency of the signal is the derivative of the
phase
.
So, if
is constant, the frequency is zero.
If
is linear,
is a sinusoid at some fixed
frequency.
If
is quadratic,
is a chirp signal whose
frequency changes linearly in time.
FM synthesis uses a more interesting , one that is
sinusoidal.
FM, meaning ``frequency modulation,'' refers to the fact that the
frequency of
changes according to the oscillations of
.
This is useful for synthesizing instrument sounds because the
proper choice of the modulating frequencies will produce a
fundamental frequency and several overtones, as many instruments do.
The general equation for an FM sound synthesizer is:
In (5), is the signal's amplitude.
It is a function of time so that the instrument sound can be made
to fade out slowly or cut off quickly.
Such a function is called an envelope.
is called the
``carrier'' frequency.
Note that when you take the derivative of
to find
,
will be a constant in that expression.
It is the frequency that would be produced without any frequency
modulation.
The parameter
is called the ``modulating" frequency.
It expresses the rate of oscillation of
.
The parameters
and
are arbitrary phase constants,
usually both set to
so that
.
The function has a less obvious purpose than the other
parameters of FM signals.
It is technically called the ``modulation index envelope.''
To see what it does, examine the expression for the
instantaneous frequency:
If is constant, then
gives the maximum
amount by which the instantaneous frequency deviates from
.
Beyond that, however, it is difficult to relate
to the
sound made by
without some rather advanced analysis.
Nonetheless, we would like to characterize
as the sum of several sinusoids instead of a single signal
whose frequency changes.
In this regard, the following comments are relevant:
when
is small
, low multiples of the carrier
frequency
have high amplitudes.
When
is large
, both low and high multiples of the
carrier frequency have high amplitudes.
The net result is that
can be used to vary the
overtone content of the instrument sound (overtones are harmonics).
When
is small, mainly low frequencies will be produced.
When
is large, higher harmonic frequencies can also be
produced.
For more details see the paper by Chowning.
There is a function in my directory called woodwenv
which
produces the functions needed to create both the and
envelopes for a clarinet sound.
The file header looks like this:
function [y1, y2] = woodwenv(a, s, r, Fs) %WOODWENV produce normalized amplitude and modulation index % functions for woodwinds % % usage: [y1, y2] = woodwenv(att, sus, rel, Fsamp); % % where att = attack TIME % sus = sustain TIME % rel = release TIME % Fsamp = sampling frequency (Hz) % returns: % y1 = (NORMALIZED) amplitude envelope % y2 = (NORMALIZED) modulation index envelope % % NOTE: attack is exponential, sustain is constant, % release is exponential
The outputs from woodwenv
are normalized so that the
minimum value is zero and the max is one.
Try the following statements to see what the function produces:
Fs = 8000; delta = 1/8000; tt = delta : delta : 0.5; [y1, y2] = woodwenv(0.1, 0.35, 0.05, Fs); subplot(2,1,1), plot(tt,y1), grid subplot(2,1,2), plot(tt,y2), grid
A new user interface controller (UIC) has been written to
assist you with the remainder of the lab. At this point go ahead
and run the UIC (called nveloper
) by typing nveloper
at the MATLAB prompt. A control panel similar
to the beatcontrol
UIC will pop up. The UIC calls the
function woodwenv.m
and allows you to adjust the attack, decay
and sustain parameters graphically. There are
also options for plotting and playing sounds. Play with the UIC
for a few minutes then go ahead and exit nveloper
.
Since the woodwind envelopes range from 0 to 1, some scaling is
necessary to make them useful in the FM synthesis equation
(5).
In this section we consider the general process of linear
re-scaling.
If we start with a normalized signal and
want to produce a new signal whose max is MAX and whose min is MIN,
then we must map 1 to MAX and 0 to MIN.
Consider the linear mapping:
Determine the relationship between and
and MAX
and MIN, so that the max and the min of
are correct.
Test this idea in MATLAB by doing the following example (where
and
):
ynorm = 0.5 + 0.5*sin( pi*[0:0.01:1]); subplot(2,1,1), plot(ynorm) ynew = 5*ynorm + 3; %<------ Linear re-scaling subplot(2,1,1), plot(ynew) max(ynorm), min(ynorm) %<--- ECHO the values max(ynew), min(ynew)
What happens if we make negative?
Write a short one-line function that implements equation
6 above. Your function should have the
following form: function y=scale(data,alpha,beta)
. After
completing the scale
function, reinvoke nveloper
. Notice the
UIC automatically detects the presence of your new function! Now the UIC
can be used to assist you in the scaling process as well as the envelope
generation. When you have finished this portion of the lab exit the UIC.
For the clarinet sound, the amplitude needs no
scaling---the MATLAB function playsound
will
automatically scale to the maximum range of the D/A converter.
Thus, is the vector
y1
.
From the plot of y1
, it should be obvious that this envelope
will cause the sound to rise quickly to a certain volume, sustain
that volume, and then quickly turn off.
The modulation index envelope, , however, does not equal
y2
.
The range for be between 2 and 4.
Furthermore, there is an inversion so that when
y2
is zero, should equal 4, and when
y2
is one, should be 2.
Using this information solve for the appropriate and
then use
nveloper
to do the scaling on the
modulation index envelope
function (I
) for a clarinet sound.
How will this affect the frequency content versus time of
the clarinet sound?
So far we have a general equation for FM signals, an amplitude envelope for the clarinet, and a modulation index envelope for the clarinet. To create the actual sound signal for the clarinet, we need to specify the additional parameters in (5).
The ratio of carrier to modulating frequency is important in
creating the sound of a specific instrument.
For the clarinet, this ratio should be 2:3.
For convenience, we define frequencies in Hz, i.e.,
and
.
The actual note frequency will be the greatest common divisor of the
carrier and modulating frequencies.
For example, when we choose
Hz and
Hz, the
synthesized signal will have a fundamental frequency of
Hz.
Write a simple M-file clarinet.m
that implements equation
(5) to synthesize a clarinet note.
Your function will be called by nveloper
and therefore
should not generate the envelopes and
(since
nveloper
already has access to these functions
through woodwenv
).
Basically, this function must implement the FM synthesis equation
(5).
The function header should look like this:
function y = clarinet(f0,aenvelope,ienvelope,duration,fs) %CLARINET produce a clarinet note signal % % usage: y = clarinet(f0,aenvelope,ienvelope,duration,fs) % % where: F0 = note frequency % aenvelope = the array holding the A(t) envelope % ienvelope = the array holding the I(t) envelope % duration = the amount of time the signal lasts % fs = the sampling rate % % NOTE: Your time variable runs from 1/fs to the duration. Starting % the time array at '0' or elsewhere will produce arrays of % different lengths.Note that the your time array must start at 1/fs instead of zero! (this is required by the
nveloper
UIC). In other
words your time array should be generated as follows:
Now when you reinvoke nveloper
you can use it to change the
frequency (the other parameters should be set as specified in the lab).
Using your clarinet( )
function, create a 250 Hz clarinet
note.
Play it with the
playsound( xnote, 8000 )
function at 8 kHz.
Does it sound like a clarinet?
How can you verify that its fundamental frequency is at 250Hz?
Describe how you can hear the frequency content changing
according to ?
Plot
versus t for comparison.
Try some other note frequencies.
Graph the entire signal and compare it to the amplitude envelope
function y1
generated by woodwenv
.
Graph about 100--200 samples from the middle of the signal and
explain what you see.