ECE 3340 CW 2-17

Name, ID

1. Fourier synthesis for time-dependent phenomena

1.1 Time-dependent signals

We have seen this previously

coef1={0.18625,0.110645,-0.02088,0.04475
,0.01658,0.00237,-0.01098,0.003489
,0.00573,0.00473,-0.00203,0.00018,0.00027
,0.00139,-0.00005,0.00154,0.00054};

coef2={0.5118,-0.0237,-0.2368,0.1724
,-0.0215,0.0301,-0.0352,-0.0098
,0.006,0.0036,0.014,-0.0092,-0.0008
,-0.0068,0.0025,0.0055,-0.0009} ;

Both are made up of the same basis functions. Only the coefficients are different.

What if we make them to be time-signal instead of space-signal? Besides the “look,” what are other differences?

Numerical approach: coding a function using Block or Module to generate a time signal

Suppose we wish to generate a time-periodic signal, what do we need to know:
1- the frequency: call it freq
2- the amplitude and phase: this is represented as the complex amplitude of a phasor:
                        A (e^(i 2 π f t)) = |A| (e^(i ϕ))  (e^(i 2 π f t))
3- the sampling rate: how often do we sample the signal as output? t is continuous, but there is no such a thing as a continuous numerical array, we have to sample time with a finite set of discrete sampling point. Let’s call it srate
4- duration: how long in time is the signal? The signal may be forever, but numerically, there is a finite size of an array of numbers to be generated.

So, below is an example of such a function, we call it signalgen for signal generator:

signalgen[{freq_,tdur_,srate_},coef_]:=Module[{nsampl,Δt,tarr
,fExpn,sigout}
,
nsampl=Round[tdur*srate];Δt=1./srate;
tarr=(Range[nsampl]-1.)*Δt;
fExpn=Table[Exp[I 2 π n  Mod[freq tarr,1]],{n,Length[coef]}];
sigout=Re[coef . fExpn];
{sigout
,ListLinePlot[Take[sigout,Round[5*srate/freq]]
,DataRange->{0,5*1./freq}
,Frame-> True, GridLines->Automatic
,FrameLabel->{"time (whichever 1/(unit of frequency))"
,"amplitude (a. u.)"}
,LabelStyle-> {18,Black}]}
];

Example how to use it: we will generate a random signal to test.

nharmonics=RandomInteger[{4,16}];
coefLogamp=RandomReal[{-1,0},nharmonics];
coefϕ=π  RandomReal[{-1,1},nharmonics];
coef=(E^(coefLogamp+ I coefϕ));
freq=440.;tdur=1.;srate=22050;
u=signalgen[{freq,tdur,srate},coef];
u[[2]]

Now, we can apply to the two sets of coefficients:

srate=22050; freq=440. ; tdur=1. ;
sigparm={freq,tdur,srate};
coef1={0.18625,0.110645,-0.02088,0.04475
,0.01658,0.00237,-0.01098,0.003489
,0.00573,0.00473,-0.00203,0.00018
,0.00027,0.00139,-0.00005,0.00154,0.00054};
coef2={0.5118,-0.0237,-0.2368,0.1724
,-0.0215,0.0301,-0.0352,-0.0098
,0.006,0.0036,0.014,-0.0092,-0.0008
,-0.0068,0.0025,0.0055,-0.0009} ;
coef1S=Drop[coef1,1]; coef2S=Drop[coef2,1];
s1=signalgen[sigparm,coef1S];
s2=signalgen[sigparm,coef2S];
Grid[{Show[#,ImageSize->350,AspectRatio-> 0.3]&
/@{s1[[2]],s2[[2]]}}]

1.2 Test signal difference as sound waves

Question

If the waveforms are treated as sound, since they both have exactly the same frequency, should they sound exactly the same (indistinguishable)? Verify your answer empirically (whether they should sound exactly or not). Empirically means you must generate the actual sounds and listen, obviously.

Answer

write your answer here (change text color to black)

1.3 Adding some more features

To make thing a bit more fun, we will add an envelope to the soundwave. It means we have a function (below) that we want to multiply to the sound signal generated above. Also, let’s generate 3 different frequencies with duration as shown below. Go back to the tutorial where you generated “happy birthday” tune to see how successive pitches with different durations are done.

envelopF[x_,td_]:=(1/(1+(E^(-x/0.2))))  ((E^(-(x-td)/0.025))/(1+(E^(-(x-td)/0.025))))*(1+0.2Sin[2 π 3.5 x]) ;

freq={261.63,392.,523.25};  tdur={0.8,0.8,0.8} ;
srate=44100; 
sigparm=Transpose[{freq,tdur,ConstantArray[srate,3]}];

coef1S={0.110645,-0.02088,0.04475
,0.01658,0.00237,-0.01098,0.003489
,0.00573,0.00473,-0.00203,0.00018
,0.00027,0.00139,-0.00005,0.00154,0.00054};
coef2S={-0.0237,-0.2368,0.1724
,-0.0215,0.0301,-0.0352,-0.0098
,0.006,0.0036,0.014,-0.0092,-0.0008
,-0.0068,0.0025,0.0055,-0.0009} ;
s1L=Flatten @ Table[su=signalgen[sigparm[[i]],coef1S][[1]];
tx=(Range[Length[su] ]-1)/srate;
su*envelopF[tx,sigparm[[i,2]]]
,{i,Length[sigparm]}];

s2L=Flatten @ Table[su=signalgen[sigparm[[i]],coef2S][[1]];
tx=(Range[Length[su] ]-1)/srate;
su*envelopF[tx,sigparm[[i,2]]]
,{i,Length[sigparm]}];

Grid[{Show[#,ImageSize->350,AspectRatio-> 0.3]&
/@{s1[[2]],s2[[2]]}
,ListPlay[#,PlayRange-> All,SampleRate->srate] & /@ {s1L,s2L}
}]

Question

Do they sound the same or difference? Is it clearer with 3 different frequencies instead of just one? Describe your observation and explain to the best of your understanding.

Answer

write your answer here (change text color to black)

2. Review - lecture break

Questions may or may not come up during the discussion.

3. Experimental sound analysis - harmonics

Here, we will do a series of experiments and explain whatever the results may be.