<<

DSP First

Lab oratory Exercise

AM and FM Sinusoidal

The ob jective of this lab is to intro duce more complicated signals that are related to the basic

sinusoid These are signals which implement mo dulation FM and amplitude mo du

lation AM are widely used in communication systems such as radio and television but they

also can be used to create interesting sounds that mimic musical instruments There are a num

nkht

ber of demonstrations on the CDROM that provide examples of these signals for many dierent

CDROM

conditions

FM Syn

thesis

Overview

Wehavespent a lot of time learning ab out the prop erties of sinusoidal of the form

o n

j j f t

xtA cos f t e Ae e

In this lab wewillcontinue to investigate sinusoidal waveforms but for more complicated signals

comp osed of sums of sinusoidal signals or sinusoids with changing frequency

Amplitude Mo dulation

If weaddseveral sinusoids each with a dierent frequency f we can express the result as

k

N N

X X

j f t

k

Z e xt A cos f t e

k k k k

k k

j

k

where Z A e is the complex exp onential amplitude The choice of f will determine the

k k k

nature of the for amplitude mo dulation we picktwo or three very close together

see Chapter

Frequency Mo dulated Signals

We will also lo ok at signals in which the frequency varies as a function of time In the constant

frequency sinusoid the argument of the cosine is also the exp onent of the complex exp onential

so the of this signal is the exp onentf t This phase function changes linearly versus

time and its time derivativeisf which equals the constant frequency of the cosine

nkht

notation for the class of signals with A generalization is available if we adopt the following

CDROM

timevarying phase

FM Syn

jt

thesis

xtA cos t efAe g

The time derivative of the phase from gives a frequency

d

t radsec t

i

dt

but we prefer units of hertz so wedivideby to dene the instantaneous frequency

d

f t t Hz

i

dt

Chirp or Linearly Swept Frequency

nkht

A chirp signal is a sinusoid whose frequency changes linearly from some lowvalue to a high one The

CDROM

formula for such a signal can b e dened by creating a complex exp onential signal with quadratic

Sp ectrograms

phase by dening tinas

Sounds

Wide

tt f t

band

FM

The derivativeof t yields an instantaneous frequency that changes linearly versus time

f tt f

i

The slop e of f t is equal to and its intercept is equal to f If the signal starts at t then

i

f is also the starting frequency The frequency variation pro duced by the timevarying phase is

called and this class of signals is called FM signals Finally since the linear

variation of the frequency can pro duce an audible sound similar to a siren or a chirp the linearFM

signals are also called chirps

Advanced Topic Sp ectrograms

It is often useful to think of signals in terms of their sp ectra A signals sp ectrum is a representation

of the frequencies present in the signal For a constant frequency sinusoid as in the sp ectrum

consists of two spikes one at f the other at f For more complicated signals the sp ectra

may be very interesting and in the case of FM the sp ectrum is considered to be timevarying

One way to represent the timevarying sp ectrum of a signal is the see Chapter in

t in short sections of the the text A sp ectrogram is found by estimating the frequency conten

nkht

signal The magnitude of the sp ectrum over individual sections is plotted as intensityor color on

CDROM

atwodimensional plot versus frequency and time

Sounds

Sp ec

There are a few imp ortantthingsto know ab out sp ectrograms

trograms

In Matlab the function specgram will compute the sp ectrogram as already explained in

Lab Typ e help specgram to learn more ab out this function and its arguments

Sp ectrograms are numerically calculated and only provide an estimate of the timevarying

frequency content of a signal There are theoretical limits on how well they can actually

representthe frequency content of a signal Lab will treat this problem when we use the

sp ectrogram to extract the frequencies of piano notes

Warmup

The instructor verication sheet may b e found at the end of this lab

Matlab Synthesis of Chirp Signals

a The following Matlab co de will syn thesize a chirp

fsamp

dt fsamp

dur

tt dt dur

psi pi tt tttt

xx real expjpsi

sound xx fsamp

Determine the range of frequencies in hertz that will b e synthesized by this Matlab script

Make asketch byhandoftheinstantaneous frequency versus time What are the minimum

and maximum frequencies that will b e heard Listen to the signal to verify that it has the

exp ected frequency content

Instructor Verication separate page

b Use the co de provided in part a to help you write a Matlab function that will synthesize

achirp signal according to the following comments

function xx mychirp f f dur fsamp

MYCHIRP generate a linearFM chirp signal

usage xx mychirp f f dur fsamp

f starting frequency

f ending frequency

dur total time duration

fsamp sampling frequency OPTIONAL default is

if nargin Allow optional input argument

fsamp

end

When unsure ab out a command use help

Generate a chirp sound to match the frequency range of the chirp in part a Listen to

the chirp using the sound function Also compute the sp ectrogram of your chirp using the

Matlab function specgramxxfsamp

Instructor Verication separate page

Lab A Chirps and Beats

Synthesize a Chirp

Use your Matlab function mychirp to synthesize a chirp signal for your lab rep ort Use the

following parameters

A total time duration of secs with a DA conversion rate of f Hz

s

The instantaneous frequency starts at Hz and ends at Hz

Listen to the signal What comments can you make regarding the sound of the chirp eg is it

linear Do es it chirp down or chirp up or b oth Create a sp ectrogram of your chirp signal Use

the sampling theorem from Chapter in the text to help explain what you hear and see

Beat Notes

In the section on beat notes in Chapter of the text we analyzed the situation in whichwe had

twosinusoidal signals of slightly dierent frequencies ie

xtA cos f f tB cos f f t

c c

In this part we will compute samples of such a signal and listen to the result

a Write an Mle called beatm that implements and has the following as its rst lines

function xx tt beatA B fc delf fsamp dur

BEAT compute samples of the sum of two cosine waves

usage

xx tt beatA B f delf fsamp dur

A amplitude of lower frequency cosine

B amplitude of higher frequency cosine

fc center frequency

delf frequency difference

fsamp sampling rate

dur total time duration in seconds

xx output vector of samples

OPTIONAL Output

tt time vector corresponding to xx

Hand in a copy of your Mle You might want to call the sumcos written in Lab to do

the calculation The function could also generate its own time vector You may elect to not

nkht

implement the second output vector tt but it is quite convenient for plotting To assist you

CDROM

in your exp eriments with b eat notes a new to ol called beatcon has b een created This user

beatconm

interfacecontrol ler actually calls your function beatm Therefore b efore you invoke beatcon

you should b e sure your Mle is free of errors Once you have the function beatm working

prop erly invoke the demoto ol by typing beatcon at the Matlab prompt A small control

panel will app ear on the screen with buttons and sliders that vary the dierent parameters

for these exercises Exp eriment with the beatcon control panel and use it to complete the

remainder of exercises in this section

fc b Test the Mle written in part a via beatcon by using the values A B

delf fsamp and dur secs Plot the rst seconds of the resulting signal

Describ e the and explain its prop erties Hand in a copyofyour plot with measure

ments of the p erio d of the envelop e and p erio d of the high frequency signal underneath the

envelop e

c For this part set delf to Hz Send the resulting signal to the DtoA converter and

listen to the sound there is a button on beatcon that will do this for you automatically

Explain the nature of the sound based on the waveform plotted in part b and on the theory

develop ed in Chapter

d Exp eriment with dierentvalues of the frequency dierence f

More on Sp ectrograms Optional

Beat notes provide an interesting waytoinvestigate the timefrequency characteristics of sp ectro

grams Although some of the mathematical details are beyond the reach of this course it is not

dicult to understand the following issue there is a fundamental tradeo b etween knowing which

frequencies are present in a signal or its sp ectrum and knowing how those frequencies vary with

time As mentioned previously in Section a sp ectrogram estimates the frequency content over

short sections of the signal Long sections give excellent frequency resolution but fail to track

frequency changes well Shorter sections have p o or frequency resolution but go o d tracking This

tradeo b etween the section length in time and frequency resolution is equivalent to Heisenburgs

Uncertainty Principle in physics More discussion of the sp ectrogram can be found in Chapter

and Lab

A b eat note signal maybeviewed as a single frequency signal whose amplitude varies with time

or as two signals with dierent constant frequencies Both views will b e useful in evaluating the

eect of window length when nding the sp ectrogram of a b eat signal

a Create and plot a b eat signal with

i f Hz

ii T sec

dur

iii f Hz or Hz

s

iv f Hz

b Find the sp ectrogram using a window length of using the commands

specgramxfsamp colormapgray

Commentonwhatyou see

c Find the sp ectrogram using a window length of using the commands

specgramxfsamp colormapgray

Commentonwhatyou see

Lab B FM Synthesis of Instrument Sounds

nkht

Frequency mo dulation FM can be used to make interesting sounds that mimic m usical instru

CDROM

ments suchas b ells wo o dwinds drums etc The goal in this lab is to implement one or two of

DEMO

FM

these FM schemes and hear the results

Synthesis

Wehave already seen that FM denes the signal xttohave a timevarying phase

xtA cos t

and that the instantaneous frequency changes according to the oscillations of t If t

is linear xt is a constantfrequency sinusoid whereas if t is quadratic xt is a chirp signal

whose frequency changes linearly in time FM music synthesis uses a more interesting t one that

is sinusoidal Since the derivativeofasinusoidal t is also sinusoidal the instantaneous frequency

t sounds b ecause the prop er choice of of xt will oscillate This is useful for synthesizing instrumen

the mo dulating frequencies will pro duce a fundamental frequency and several overtones as many

instruments do

The general equation for an FM sound synthesizer is

xtAt cos f t I tcosf t

c m m c

where At is the signals amplitude It is a function of time so that the instrument sound can b e

made to fade out slowly or cut o quickly Sucha function is called an envelope The parameter

f is called the carrier frequency Note that when you take the derivativeof ttondf t

c i

d

f t t

i

dt

d

f t I tcosf t

c m m c

dt

dI

cosf t f I tf sinf t

m m c m m m

dt

f will b e a constant in that expression It is the frequency that would b e pro duced without any

c

frequency mo dulation The parameter f is called the modulating frequency It expresses the rate

m

of oscillation of f t The parameters and are arbitrary phase constants usually b oth set

i m c

to so that x

The function I t has a less obvious purp ose than the other FM parameters in It is

technically called the modulation index envelope To see what it do es examine the expression

for the instantaneous frequency The quantity I tf multiplies a sinusoidal variation of the

m

dI

frequency If I t is constantor is relatively small then I tf gives the maximum amountby

m

dt

which the instantaneous frequency deviates from f Beyond that however it is dicult to relate

c

I t to the sound made by xt without some rather tedious mathematical analysis

In our study of signals we would like to characterize xt as the sum of several constant

frequency sinusoids instead of a single signal whose frequency changes In this regard the following

comments are relevant when I t is small eg I low multiples of the carrier frequency

I t is large I both low and high multiples of the carrier f have high amplitudes When

c

frequency have high amplitudes The net result is that I t can be used to vary the harmonic

content of the instrument sound called overtones When I t is small mainly low frequencies will

b e pro duced When I t is large higher harmonic frequencies can also b e pro duced Since I t is

a function of time the harmonic contentwillchange with time For more details see the pap er by

Chowning

Generating the Bell Envelop es

Nowwetake the general FM synthesis formula and sp ecialize for the case of a b ell sound The

amplitude envelop e At and the mo dulation index envelop e I t for the b ell are both decaying

exp onentials That is they b oth have the following form

t

y te

where is a parameter that controls the decay rate of the exp onential Notice that y and

y e so is the time it takes a signal of the form to decayto e of its initial

value For this reason the parameter is called the time constant

Use to write a Matlab function that will generate adecaying exp onential to b e used later

in synthesizing a b ell sound The le header should lo ok like this

Ref John M Chowning The Synthesis of Complex Audio Sp ectra by means of Frequency Mo dulation Journal

of the Audio Engineering Societyvol no Sept pp

function yy bellenvtau dur fsamp

BELLENV produces envelope function for bell sounds

usage yy bellenvtau dur fsamp

where tau time constant

dur duration of the envelope

fsamp sampling frequency

returns

yy decaying exponential envelope

note produces exponential decay for positive tau

The function will b e one or two lines of Matlab co de The rst line should dene your time vector

based on fsamp and dur and the second generates the exp onential

The b ells amplitude envelop e At and mo dulation index envelop e I t are identical up to a

scale factor

t t

AtA e and I tI e

Hence one call to the bellenv function will generate the shap e for b oth envelop es

Parameters for the Bell

Now that we have the b ells amplitude and mo dulation index envelop es we can create the actual

sound signal for the b ell by sp ecifying all the parameters in the general FM synthesis formula

The frequencies f and f must be given numerical values The ratio of carrier to mo dulating

c m

frequency is imp ortant in creating the sound of a sp ecic instrument For the bell a good choice

for this ratio is eg f Hz and f Hz

c m

Now write a simple Mle bellm that implements to synthesize a b ell sound Your function

t t

and I tI e should call bellenvm to generate AtA e

function xx bellff Io tau dur fsamp

BELL produce a bell sound

usage xx bellff Io tau dur fsamp

where ff frequency vector containing fc and fm

Io scale factor for modulation index

tau decay parameter for At and It

dur duration in sec of the output signal

fsamp sampling rate

The Bell Sound

Test your bell function using the parameters of case in the table Play it with the sound

function at Hz Do es it sound like a b ell The value of I for scaling the mo dulation



A higher sampling rate of Hz is used b ecause the signal contains many harmonics some of which might

alias if a lower f were used You should exp erimentwithlower values of f to see if you can hear a dierence eg

s s

index envelop e is known to give a distinctive sound Later on you can exp eriment with other values

to get avarietyofbells

case f Hz f Hz I sec T sec f Hz

c m s

dur

The frequency sp ectrum of the bell sound is very complicated but it do es consist of sp ectral

lines which can be seen with a sp ectrogram Among these frequencies one sp ectral line will

dominate what wehear Wewould call this the note frequency of the b ell It is tempting to guess

that the note frequency will b e equal to f but you will have to exp eriment to nd the true answer

c

It might be f or it might be something elsep erhaps the fundamental frequency which is the

m

greatest common divisor of f and f

c m

For each case in the table do the following

a Listen to the sound byplaying it with the sound function

b Calculate the fundamental frequency of the note b eing played Explain howy ou can verify

by listening that you have the correct fundamental frequency

c Describ e howyou can hear the frequency contentchanging according to I t Plot f tversus

i

t for comparison

d Display a sp ectrogram of the signal Describ e how the frequency content changes and how

that change is related to I t Point out the harmonic structure of the sp ectrogram and

calculate the fundamental frequency f

e Plot the entire signal and compare it to the envelop e At generated by bellenv

f Plot ab out samples from the middle of the signal and explain what you see esp ecially

the frequency variation

the plots for two caseschoose one of the rst four and one If you are making a lab report do

of the last two Write up an explanation only for the two that you choose

Comments ab out the Bell

Cases and are extremes for cho osing the decay rate In case the waveform do es not

decay very much over the course of three seconds and sounds a little like a sum of harmonically

related sinusoids With a faster decay rate as in case we get a p ercussionlike sound

Mo difying the fundamental frequency f determined in part d ab ove should have a noticeable

eect on the tone you hear Try some dierentvalues for f bychanging f and f but still in the

c m

ratio of Describ e what you hear

Finally exp eriment with dierent carrier to mo dulation frequency ratios For example in his

pap er Chowning uses a fundamental frequency of f Hz and a carrier to mo dulation frequency

ratio of Try this and a few other values Which parameters sound b est to you

f Hz

s

Wo o dwinds

As an alternativeto the b ell sounds this section shows how dierent parameters in the same FM

synthesis formula will yield a clarinet sound or other wo o dwinds

nkht

Generating the Envelop es for Woodwinds

CDROM

There is a function on the CDROM called woodwenv which pro duces the functions needed to

woodwenvm

create b oth the AtandI tenvelop es for a clarinet sound The le header lo oks like this

function y y woodwenvatt sus rel fsamp

WOODWENV produce normalized amplitude and modulation index

functions for woodwinds

usage y y woodwenvatt sus rel fsamp

where att attack TIME

sus sustain TIME

rel release TIME

fsamp sampling frequency Hz

returns

y NORMALIZED amplitude envelope

y 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 pro duces

fsamp

Ts fsamp

tt delta Ts

y y woodwenv fsamp

subplot plottty grid on

subplot plottty grid on

Scaling the Clarinet Envelop es

Since the wo o dwind envelop es pro duced by woodwenv range from to some scaling is necessary

to make them useful in the FM synthesis equation In this section we consider the general

pro cess of linear rescaling If we start with a normalized signal y t and want to pro duce a

norm

new signal whose max is y and whose min is y thenwe must map to y and to y

min max min max

Consider the linear mapping

y ty t

new norm

Determine the relationship b etween and and y and y so that the max and the min of

max min

y t are correct

new

Test this idea in Matlab by doing the following example where and

ynorm sin pi

subplot plotynorm

alpha beta

ynew alphaynorm beta Linear rescaling

subplot plotynew

maxynorm minynorm ECHO the values

maxynew minynew

What happ ens if wemake negative

Write a short oneline function that implements ab ove Your function should have the following

form function y scaledata alpha beta

Clarinet Envelop es

For the clarinet sound the amplitude At needs no scalingthe Matlab function sound will

automatically scale to the maximum range of the DA converter Thus At equals the vector y

From the plot of y shown in Fig it should b e ob vious that this envelop e will cause the sound

to rise quickly to a certain volume sustain that volume and then quickly turn o

y1 Envelope y2 Envelope 1 1

0.5 0.5

0 0 0 0.5 1 1.5 2 0 0.5 1 1.5 2 A(t) Envelope I(t) Envelope 1 4

0.5 2

0 0 0 0.5 1 1.5 2 0 0.5 1 1.5 2

time (t) time (t)

Figure Envelop es for the wo o dwinds The functions At and I t are pro duced by scaling y

and y the outputs of woodwenv

The mo dulation index envelop e I t however do es not equal y The range for I t lies b etween

and as in Fig Furthermore there is an inversion so that when y is zero I t should equal

and when y is one I t should b e Using this information solve for the appropriate and

then use scale to pro duce the mo dulation index envelop e function I for a clarinet sound

Parameters for the Clarinet

So far we have a general equation for FM signals an amplitude envelop e for the clarinet and a

mo dulation index envelop e for the clarinet To create the actual sound signal for the clarinet we

need to sp ecify the additional parameters in The ratio of carrier to mo dulating frequency is

imp ortant in creating the sound of a sp ecic instrument For the clarinet this ratio should be

The actual note frequency will b e the greatest common divisor of the carrier and mo dulating

frequencies For example when we cho ose f Hz and f Hz the synthesized signal

c m

will have a fundamental frequency of f Hz

Write a simple Mle clarinetm that implementstheFMsynthesis equation to synthesize

a clarinet note Your function should generate the envelop es At and I t using textttscale and

textttwoodwenv The function header should lo ok like this

function yy clarinetf Aenv Ienv dur fsamp

CLARINET produce a clarinet note signal

usage yy clarinetf Aenv Ienv dur fsamp

where f note frequency

Aenv the array holding the At envelope

Ienv the array holding the It envelope

dur the amount of time the signal lasts

fsamp the sampling rate

Exp eriment with the Clarinet Sound

Using your clarinet function create a Hz clarinet note with f or Hz Play

s

it with the sound xnote fs function Do es it sound like a clarinet Howcanyou verify that

its fundamental frequency is at Hz

Explain how the mo dulation index I t will aect the frequency content versus time of the

clarinet sound Describ e howyou can hear the frequency contentchanging according to I t Plot

the instantaneous frequency f t versus t for comparison

i

Plot the entire signal and compare it to the amplitude envelop e function y in Fig Plot

ab out samples from the middle of the signal and explain what you see

Finally synthesize other note frequencies For example make the Cma jor scale dened in

Lab consisting of seven consecutive notes

Lab

Instructor Verication Sheet

Staple this page to the end of your Lab Rep ort

Name Date

Part Explain chirp signal

Veried

Part Complete the mychirpm function

Veried