Workshop W64 Fourier and Wavelet Analysis · 2012-08-22 · 1 Advanced Lab Fourier Analysis and...
Transcript of Workshop W64 Fourier and Wavelet Analysis · 2012-08-22 · 1 Advanced Lab Fourier Analysis and...
1
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Workshop W64Workshop W64"Fourier and Wavelet Analysis""Fourier and Wavelet Analysis"
Joseph J. Trout, Ph.D.Richard College of NJAssistant Professor of PhysicsNAMS – Physics [email protected] 2012 Summer MeetingPhiladelphia, PennsylvaniaDC06Tue 07/31, 10:20AM - 10:30AM
2
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
ABSTRACT:In this laboratory experiment, techniques in data analysis using Fourier and wavelet analysis are introduced. First the students review Fourier series. Sound recordings of tuning forks are then made using Matlab and the students use a simple code to find the amplitudes of the frequencies present in the recording. The students then repeat the analysis using Matlab's Fast Fourier Transform utility and compare the results. Wavelets are then introduced and the recording are then analyzed using wavelet techniques to understand the similarities and differences between Fourier analysis and wavelet analysis. Finally, topics of "noise" and "filtering" are introduced and voice recordings or recordings or music are made and analyzed.
3
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
The Fourier TransformThe Fourier TransformIf f is a continuous differentialable function with ∫
−∞
∞
∣f t ∣dt∞ , then:
f x = 12
∫−∞
∞f ei x d
where f (the Fourier Transform of f ) is given by:
f x = 12
∫−∞
∞
f t e−i td t
4
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
The Discrete Fourier TransformThe Discrete Fourier TransformLet y={y j }j=−∞
∞ ∈S n ( where S n is the set of n -periodic sequences ofcomplex numbers ). The discrete Fourier transform of y is the sequence
F n {y }k=yk , where:
yk=∑j=0
n−1
y jwij with w=e
2 in
In detail: the DFT is the sequence:
yk=∑j=0
n−1
y j e−2 i k j
n
5
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Other Wavelets - DaubechiesOther Wavelets - Daubechies
6
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
7
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Comparison of DWT to FFTComparison of DWT to FFTf t =2 sin 2 f 1 t 3sin 2 f 2 t sin 2 f 3 t
f 1=5Hzf 2=20Hzf 3=80Hz
8
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Comparison of DWT to FFTComparison of DWT to FFT
f t =2sin 2 f 1 t 3 sin 2 f 2 t sin 2 f 3 t f 1=5Hzf 2=20Hzf 3=80Hz
9
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Comparison of DWT to FFTComparison of DWT to FFT
f t =2sin 2 f 1 t 3 sin 2 f 2 t sin 2 f 3 t f 1=5Hzf 2=20Hzf 3=80Hz
10
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Comparison of DWT to FFTComparison of DWT to FFT
f t =2sin 2 f 1 t 3 sin 2 f 2 t f 1=5Hzf 2=20Hzf 3=80Hzf t =2sin 2 f 1 t sin 2 f 3 t
11
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Comparison of DWT to FFTComparison of DWT to FFT
f t =2sin 2 f 1 t 3 sin 2 f 2 t f 1=5Hzf 2=20Hzf 3=80Hz
f t =2sin 2 f 1 t sin 2 f 3 t
12
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Comparison of DWT to FFTComparison of DWT to FFT
f t =2sin 2 f 1 t 3 sin 2 f 2 t f 1=5Hzf 2=20Hzf 3=80Hzf t =2sin 2 f 1 t sin 2 f 3 t
13
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Fast Fourier Transform ( FFT)Fast Fourier Transform ( FFT)
Original Signal discretized with 28=256 points. 0≤t≤2
14
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Fast Fourier Transform ( FFT)Fast Fourier Transform ( FFT)
Original Signal discretized with 28=256 points. 0≤t≤2Sun Performance Library FFT used to generate the Discrete Fourier Coefficients yk , k=0,. .. ,255 .Noise has a frequency that is larger than 5 cycles per 2 interval.
15
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Fast Fourier Transform ( FFT) Fast Fourier Transform ( FFT)
Use to Filter out Noise.Use to Filter out Noise.
Function: y t =e−cos t 2
sin 2t2 cos 4t0.4 sin t sin 50 t
Original Signal discretized with 28=256 points. 0≤t≤2Sun Performance Library FFT used to generate the Discrete Fourier Coefficients yk , k=0,. .. ,255 .Noise has a frequency that is larger than 5 cycles per 2 interval.Keep only y k for 0≤k≤5 and set yk=0.0 for 6≤k≤128 .By Theorem, yk=0 for 128≤k≤250 . Applying FFT to filter yk
Filtered by keeping first five coefficients and completinginverse FFT.
Error=∣∣y− yc∣∣l2∣∣y∣∣l2
=0.26
16
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Using Wavelets to Filter DataUsing Wavelets to Filter Data
Original Signal discretized with 28=256 points. 0≤t≤2Numerical Recipes Daub 8 used to generate wavelet coefficients yk , k=0,. .. ,255 .Keep only wavelet coefficients with a magnitude > 1 .
17
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
18
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
19
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
20
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
21
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
22
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
23
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
24
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Pre-Lab: Fourier Series
25
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Computation of Fourier Series Computation of Fourier Series on Interval -on Interval -aa <= x <= + <= x <= +aa
f x =ao∑k=1
∞ [ak coska tbk sin ka t]a0=
12a∫−a
a
f t dt
ak=1a∫−a
a
f t cosk ta dtbk=
1a∫−a
a
f t sink ta dt
Fourier Coefficients of the Function f(x):
26
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab Computation of Fourier Series Computation of Fourier Series
on Interval -on Interval -aa <= x <= + <= x <= +aa
f x =ao∑k=1
∞ [ak coska tbk sin ka t]a0=
1N Δ t∑i=0
N
f iΔ t
ak=1
N Δ t∑i=0
N
f i cos(2π F k tN Δ t )dt
bk=1a∫−a
a
f ( t )sin( k π ta )dt
Approximations Fourier Coefficients of the Function f(x):
27
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
f (t )= ∑n=odd
1n
sin (2π n t )
-1.5
-1
-0.5
0
0.5
1
1.5
Square Wave
t
f(t)
+1
28
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
>> t=(0:199)*0.01;
>> y1=(1/1)*sin(2*pi*1*t);>> y3=(1/3)*sin(2*pi*3*t);>> y5=(1/5)*sin(2*pi*5*t);>> y7=(1/7)*sin(2*pi*7*t);>> y9=(1/9)*sin(2*pi*9*t);>> y11=(1/11)*sin(2*pi*11*t);>> y13=(1/13)*sin(2*pi*13*t);>> yt=y1+y3+y5+y7+y9+y11+y13;
>> plot(t,y1,t,y3,t,y5,t,y7,t,y9,t,y11,t,y13);
>> hold all;
>> plot(t,yt,'LineWidth',4);
>> ylabel('y(t)');>> xlabel('t');
29
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
0 0 . 2 0 . 4 0 . 6 0 . 8 1 1 . 2 1 . 4 1 . 6 1 . 8 2- 1
- 0 . 8
- 0 . 6
- 0 . 4
- 0 . 2
0
0 . 2
0 . 4
0 . 6
0 . 8
1
t
y(t)
30
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
The first part of the lab uses tuning forks to record the sound. This provides the students a chance to learn about recording sound and gives a physical meaning to the analysis.
31
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
These recordings can be made in Matlab using:
audiorecorder
>> recObj1=audiorecorder
recObj1 =
audiorecorder handle
Properties: SampleRate: 8000 BitsPerSample: 8 NumberOfChannels: 1 DeviceID: -1 CurrentSample: 1 TotalSamples: 0 Running: 'off' StartFcn: [] StopFcn: [] TimerFcn: [] TimerPeriod: 0.0500 Tag: '' UserData: [] Type: 'audiorecorder'
32
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
You can record using: recordblocking
>> disp('Start recording for 5 seconds')Start recording for 5 seconds>> recordblocking(recObj1,5);>> disp('Recording has finished');Recording has finished>> disp('Play Recording');Play Recording>> play(recObj1);
33
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
You can play recording using: play
>> disp('Start recording for 5 seconds')Start recording for 5 seconds>> recordblocking(recObj1,5);>> disp('Recording has finished');Recording has finished>> disp('Play Recording');Play Recording>> play(recObj1);
34
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Make an data array of amplitudes from sound recording: getaudiodata
>> tempRecord = getaudiodata(recObj1);
Caution: Not using semicolon (;) will print all the values.
35
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
You can “play” a numerical data array using : sound
>> sound(tempRecord);
36
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
You can plot the data array using : plot
>>plot(tempRecord);
37
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
0 0 . 5 1 1 . 5 2 2 . 5 3 3 . 5 4
x 1 04
- 0 . 5
- 0 . 4
- 0 . 3
- 0 . 2
- 0 . 1
0
0 . 1
0 . 2
0 . 3
0 . 4
0 . 5
38
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
You can print the data using: fprintf
fprintf('%f \n', tempRecord(1:300));0.000000 0.000000 0.000000 ….
This statement will print first 300 data elements. Note array index starts at 1 (one). Caution: A recording can have zero amplitude for the first several elements.
39
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Should use powers of two to do the analysis. For this part of lab, using tuning forks, it is easier to make long recordings and crop to a power of two data points. Stay away from beginning and end or recording.
>> Record1=tempRecord(10001:12048);
40
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Also, we know the sampling frequency so we can also set up the time variables at the same time.
>> recObj1
recObj1 =
audiorecorder handle
Properties: SampleRate: 8000 BitsPerSample: 8 NumberOfChannels: 1 DeviceID: -1 CurrentSample: 1 TotalSamples: 40000 ….
41
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
>> Record1=tempRecord(1:2048);>> Record1=tempRecord(5001:7048);>> Fs=8000;>> Ts=1/Fs;>> N=numel(Record1)
N =
2048
>> t=(0:N-1)*Ts;>>
42
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
And you can plot the “cropped” data.
>> plot(t(1:100),Record1(1:100));>> title('512 Hz Tuning Fork');>> xlabel('Time(s)');>> ylabel('Relative Amplitude');
43
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
0 0 . 0 0 2 0 . 0 0 4 0 . 0 0 6 0 . 0 0 8 0 . 0 1 0 . 0 1 2 0 . 0 1 4- 0 . 0 8
- 0 . 0 6
- 0 . 0 4
- 0 . 0 2
0
0 . 0 2
0 . 0 4
0 . 0 6
0 . 0 85 1 2 H z T u n i n g F o r k
T i m e ( s )
Rel
ativ
e A
mpl
itude
44
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
0 0 . 0 0 2 0 . 0 0 4 0 . 0 0 6 0 . 0 0 8 0 . 0 1 0 . 0 1 2 0 . 0 1 4- 0 . 0 8
- 0 . 0 6
- 0 . 0 4
- 0 . 0 2
0
0 . 0 2
0 . 0 4
0 . 0 6
0 . 0 85 1 2 H z T u n i n g F o r k
T i m e ( s )
Rel
ativ
e A
mpl
itude 6 cycles
f =6cycles0.012 s
≈500Hz
45
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
f=(Fs)*linspace(0,1,nfft/2+1);for i = 1:(nfft/2+1)a(i)=0;b(i)=0;for j=1:Na(i)=a(i)+Record1(j)*cos(2*pi*f(i)*t(j));b(i)=b(i)+Record1(j)*sin(2*pi*f(i)*t(i));enda(i)=a(i)/N;b(i)=b(i)/N;end
46
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
>> for i= 1:(nfft/2+1)A(i)=sqrt(a(i)*a(i)+b(i)*b(i));pow(i)=(2*A(i))*(2*A(i));end
47
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
plot(f,pow);
0 1 0 0 0 2 0 0 0 3 0 0 0 4 0 0 0 5 0 0 0 6 0 0 0 7 0 0 0 8 0 0 00
0 . 5
1
1 . 5
2
2 . 5
3
3 . 5
4x 1 0
- 3
48
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
bar(f(125:150),pow(125:150));title('Power Spectrum');xlabel('Frequency(Hz)');ylabel('Amplitude Squared');
49
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
9 5 0 1 0 0 0 1 0 5 0 1 1 0 0 1 1 5 0 1 2 0 00
0 . 5
1
1 . 5
2
2 . 5
3
3 . 5
4x 1 0
- 3 P o w e r S p e c t r u m
F r e q u e n c y ( H z )
Am
plitu
de S
quar
ed
50
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
l>> for i = 125:140fprintf('Freq= %f Hz Power= %f \n', f(i),pow(i));endFreq= 968.750000 Hz Power= 0.000004 Freq= 976.562500 Hz Power= 0.000007 Freq= 984.375000 Hz Power= 0.000009 Freq= 992.187500 Hz Power= 0.000012 Freq= 1000.000000 Hz Power= 0.000022 Freq= 1007.812500 Hz Power= 0.000058 Freq= 1015.625000 Hz Power= 0.000300 Freq= 1023.437500 Hz Power= 0.003640 Freq= 1031.250000 Hz Power= 0.000121 Freq= 1039.062500 Hz Power= 0.000034 Freq= 1046.875000 Hz Power= 0.000017 Freq= 1054.687500 Hz Power= 0.000011 Freq= 1062.500000 Hz Power= 0.000006 Freq= 1070.312500 Hz Power= 0.000005 Freq= 1078.125000 Hz Power= 0.000004 Freq= 1085.937500 Hz Power= 0.000003
51
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
>>nfft=2^(nextpow2(length(Record1)));fftAtemp=fft(Record1,nfft);NumUniqPts=ceil((nfft+1)/2)
NumUniqPts =
1025
fftA=fftAtemp(1:NumUniqPts);fftA=abs(fftA)/length(Record1);fftA=fftA.^2;fftA(2:end-1)=fftA(2:end-1)*2;f=Fs/2*linspace(0,1,nfft/2+1);
52
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
bar(f(125:150),fftA(125:150));title('Power Spectrum using Matlab FFT');xlabel('Frequency(Hz)');ylabel('Amplitude Squared');
53
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
9 5 0 1 0 0 0 1 0 5 0 1 1 0 0 1 1 5 0 1 2 0 00
0 . 5
1
1 . 5
2
2 . 5x 1 0
- 3 P o w e r S p e c t r u m u s i n g M a t l a b F F T
F r e q u e n c y ( H z )
Am
plitu
de S
quar
ed
54
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
>> for i = 125:140fprintf('Freq= %f Hz Power= %f \n', f(i),fftA(i));endFreq= 968.750000 Hz Power= 0.000001 Freq= 976.562500 Hz Power= 0.000002 Freq= 984.375000 Hz Power= 0.000003 Freq= 992.187500 Hz Power= 0.000004 Freq= 1000.000000 Hz Power= 0.000006 Freq= 1007.812500 Hz Power= 0.000017 Freq= 1015.625000 Hz Power= 0.000077 Freq= 1023.437500 Hz Power= 0.002174 Freq= 1031.250000 Hz Power= 0.000040 Freq= 1039.062500 Hz Power= 0.000010 Freq= 1046.875000 Hz Power= 0.000005 Freq= 1054.687500 Hz Power= 0.000003 Freq= 1062.500000 Hz Power= 0.000002 Freq= 1070.312500 Hz Power= 0.000001 Freq= 1078.125000 Hz Power= 0.000001 Freq= 1085.937500 Hz Power= 0.000001
55
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
f(25:30)
ans =
187.5000 195.3125 203.1250 210.9375 218.7500 226.5625
Record2=0.2*sin(2*pi*195.3125*t);plot(Record2(1:100));fftAtemp=fft(Record2,nfft);fftA=fftAtemp(1:NumUniqPts);fftA=abs(fftA)/length(Record2);fftA(2:end-1)=fftA(2:end-1)*2;fftA=fftA.^2;bar(f,fftA);bar(f(20:50),fftA(20:50));title('F=195.3125');xlabel('Frequency(Hz)');ylabel('Relataive Amplitude');
56
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
1 0 0 1 5 0 2 0 0 2 5 0 3 0 0 3 5 0 4 0 00
0 . 0 0 5
0 . 0 1
0 . 0 1 5
0 . 0 2
0 . 0 2 5
0 . 0 3
0 . 0 3 5
0 . 0 4
0 . 0 4 5F = 1 9 5 . 3 1 2 5
F r e q u e n c y ( H z )
Rel
atai
ve A
mpl
itude
57
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
f(25:30)
ans =
187.5000 195.3125 203.1250 210.9375 218.7500 226.5625
Record2=0.2*sin(2*pi*197*t);plot(Record2(1:100));fftAtemp=fft(Record2,nfft);fftA=fftAtemp(1:NumUniqPts);fftA=abs(fftA)/length(Record2);fftA(2:end-1)=fftA(2:end-1)*2;fftA=fftA.^2;bar(f,fftA);bar(f(20:50),fftA(20:50));title('F=197');xlabel('Frequency(Hz)');ylabel('Relataive Amplitude');
58
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
1 0 0 1 5 0 2 0 0 2 5 0 3 0 0 3 5 0 4 0 00
0 . 0 0 5
0 . 0 1
0 . 0 1 5
0 . 0 2
0 . 0 2 5
0 . 0 3
0 . 0 3 5F = 1 9 7
F r e q u e n c y ( H z )
Rel
atai
ve A
mpl
itude
59
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Wavelet Analysis
60
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Trial>> N=20148;Trial>> Fs=8000;Trial>> Ts=1/Fs;Trial>> t=(0:N-1)*Ts;Trial>> y=3*sin(2*pi*247*t);Trial>> signal=struct('val',y,'period',Ts);Trial>> cwtS1(signal,'wavelet','morl');Error using subsindexFunction 'subsindex' is not defined for values of class'struct'. Trial>> cwtS1=cwtft(signal,'wavelet','morl');
Wavelet Prelab:
61
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Wavelet Prelab:
>> cwtS1
cwtS1 =
cfs: [30x20148 double] scales: [1x30 double] omega: [1x20148 double] meanSIG: 4.0313e-05 dt: 1.2500e-04 wav: 'morl'
62
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Wavelet Prelab:
for i=1:numel(cwtS1.scales)figure;plot(t,real(cwtS1.cfs(i,:)));end
63
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Wavelet Prelab:
Trial>> scales=cwtS1.scales;Trial>> wo=6;Trial>> MorFFac=4*pi/(wo+sqrt(2+wo*wo));Trial>> freq=1./(scales.*MorFFac);Trial>> contour(t*1000,freq,real(cwtS1.cfs));Trial>> Trial>> contour(t*1000,freq,real(cwtS1.cfs));Trial>> axis([10 40 150 400]);Trial>> title('Contour Plot');Trial>> ylabel('Pseudo-Frequency (Hz)');Trial>> xlabel('Time(ms)');
64
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
65
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
N=2048;Fs=8000;Ts=1/Fs;t=(0:N-1)*Ts;y=3*sin(2*pi*247*t);signal=struct('val',y,'period',Ts);cwtS1=cwtft(signal,'wavelet','morl');cwtS1scales=cwtS1.scales;wo=6;MorFFac=4*pi/(wo+sqrt(2+wo*wo));freq=1./(scales*MorFFac);contour(t*1000,freq,real(cwtS1.cfs));axis([10 40 150 400]);title('Contour Plot');ylabel('Pseudo-Frequency (Hz)');xlabel('Time(ms)');
66
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Trial>> freq
freq =
1.0e+03 *
Columns 1 through 8
3.8721 2.7618 1.9699 1.4050 1.0022 0.7148 0.5098 0.3636
Columns 9 through 16
0.2594 0.1850 0.1320 0.0941 0.0671 0.0479 0.0342 0.0244
Columns 17 through 23
0.0174 0.0124 0.0088 0.0063 0.0045 0.0032 0.0023
Trial>> plot(t,real(cwtS1.cfs(9,:)));Trial>> axis([0 0.05 -18 18]);Trial>>
67
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Trial>> recObj3=audiorecorder
recObj3 =
audiorecorder handle
Properties: SampleRate: 8000 BitsPerSample: 8 NumberOfChannels: 1 DeviceID: -1 CurrentSample: 1 TotalSamples: 0 Running: 'off' StartFcn: [] StopFcn: [] TimerFcn: [] TimerPeriod: 0.0500 Tag: '' UserData: [] Type: 'audiorecorder'
Methods, Events, Superclasses
Data Collection
68
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Trial>> recObj3=audiorecorder
Trial>> Fs=8000;Trial>> Ts=1/Fs;Trial>> recordblocking(recObj3,5)Trial>> tempRecord = getaudiodata(recObj3);Trial>> Record3=tempRecord(1001:3048);
69
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Trial>> N=numel(Record3)
N =
2048
Trial>> t=(0:N-1)*Ts;Trial>> signal3=struct('val',transpose(Record3),'period',Ts);Trial>> cwtS3=cwtft(signal3,'wavelet','morl');Trial>> cwtS3
cwtS3 =
cfs: [23x2048 double] scales: [1x23 double] omega: [1x2048 double] meanSIG: 0.0130 dt: 1.2500e-04 wav: 'morl'
70
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Trial>> scales=cwtS3.scales;Trial>> wo=6;Trial>> MorFFac=4*pi/(wo+sqrt(2+wo*wo));Trial>> freq=1./(scales.*MorFFac);
Trial>> contour(t*1000,freq,real(cwtS3.cfs));Trial>> axis([150 200 0 800])
71
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
1 5 0 1 5 5 1 6 0 1 6 5 1 7 0 1 7 5 1 8 0 1 8 5 1 9 0 1 9 5 2 0 00
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 0 0
72
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Trial>> nfft=2^(nextpow2(length(Record3)));Trial>> X=fft(Record3,nfft);Trial>> NumUniqPts=ceil((nfft+1)/2)
NumUniqPts =
1025
Trial>> f=Fs*linspace(0,1,NumUniqPts);Trial>> power=4*(X.*conj(X))/(nfft*nfft);Trial>> power(1)=4*(X(1).*conj(X(1)))/(nfft*nfft);
73
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Trial>> nfft=2^(nextpow2(length(Record3)));Trial>> X=fft(Record3,nfft);Trial>> NumUniqPts=ceil((nfft+1)/2)
NumUniqPts =
1025
Trial>> f=Fs*linspace(0,1,NumUniqPts);Trial>> power=4*(X.*conj(X))/(nfft*nfft);Trial>> power(1)=4*(X(1).*conj(X(1)))/(nfft*nfft);Trial>> plot(f(1:NumUniqPts),power(1:NumUniqPts));Trial>> plot(f(1:300),power(1:300));Trial>> title('Power Spectrum');Trial>> xlabel('Frequency (Hz)');Trial>> ylabel('Relative Amplitudes');
74
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
0 5 0 0 1 0 0 0 1 5 0 0 2 0 0 0 2 5 0 00
0 . 5
1
1 . 5
2
2 . 5
3x 1 0
- 3 P o w e r S p e c t r u m
F r e q u e n c y ( H z )
Rel
ativ
e A
mpl
itude
s
75
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
76
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
77
Advanced Lab Fourier Advanced Lab Fourier Analysis and Wavelet Analysis and Wavelet Analysis Using MatlabAnalysis Using Matlab
Questions?