Upload
rv-abejo-angagan
View
219
Download
0
Embed Size (px)
Citation preview
8/14/2019 Lab 6 DFT
1/10
Objectives
BY the end of the session the students should be able to:
Apply programming skills in MATLAB
Understand the different function and its usesKnow how to create user defined function
Learn how to design solution in machine problem using MATLAB
Tools Required
1. Computer Workstation
2. MATLAB Software with Signal Processing Toolbox
Exercises
Given the sinusoid
() (
)
obtained by sampling the analog signal
x(t) = 2 _ sin2000pt
with a sampling rate of fs= 8,000 Hz,
a. Use the MATLAB DFT to compute the signal spectrum with thefrequency resolution to be
equal to or less than 8 Hz.
b. Use the MATLAB FFT and zero padding to compute the signal spectrum, assuming that the
data samples are available in (1).
Solution:
a. The number of data points is found to be N =
=
1000. There isno zero padding
needed if we use the DFT formula. Detailed implementationis given in Program 4.1. The first
EXPERIMENT ITLE
Digital Signal Processing Laboratory-Module NO. 5
DISCRETE FOURIER TRANSFORMSignals, Spectra, Signal Processing
Laboratory
ECES4421L
8/14/2019 Lab 6 DFT
2/10
8/14/2019 Lab 6 DFT
3/10
8/14/2019 Lab 6 DFT
4/10
>>subplot(2,1,2);plot(f,P(1: N/2+1));gridxlabel('Frequency (Hz)'); ylabel('Power spectrum (DFT)');
>> x = [x, zeros(1,24)];
>> N = length(x);>>xf = abs(fft(x))/N;
>> P = xf.*xf;
>> f = [0: 1:N-1]*fs/N;
>>subplot(2,1,1); plot(f,xf);grid
xlabel('Frequency (Hz)'); ylabel('Amplitude spectrum (FFT)');
>>subplot(2,1,2);plot(f,P);grid
0 500 1000 1500 2000 2500 3000 3500 40000
1
2
3
4
Frequency (Hz)
Powerspe
ctrum(
DFT)
0 1000 2000 3000 4000 5000 6000 7000 80000
0.5
1
Frequency (Hz)
Amplitudespectrum(
FFT)
8/14/2019 Lab 6 DFT
5/10
xlabel('Frequency (Hz)'); ylabel('Power spectrum (FFT)');
>>xf(2: N) = 2*xf(2: N);
>> P = xf.*xf;
>> f = [0: 1:N/2]*fs/N;
>>subplot(2,1,1); plot(f,xf(1: N/2 + 1));gridxlabel('Frequency (Hz)'); ylabel('Amplitude spectrum (FFT)');
>>subplot(2,1,2);plot(f,P(1: N/2 + 1));grid
xlabel('Frequency (Hz)'); ylabel('Power spectrum (FFT)');
0 1000 2000 3000 4000 5000 6000 7000 80000
0.5
1
Frequency (Hz)
Powerspectrum
(FFT)
0 500 1000 1500 2000 2500 3000 3500 40000
0.5
1
1.5
2
Frequency (Hz)
Amplitudespectrum(
FFT)
8/14/2019 Lab 6 DFT
6/10
8/14/2019 Lab 6 DFT
7/10
2. Apply the FFT algorithm N = length(x); index_t = [0: 1: N - 1]; f = [0: N - 1]*8000/N; xf=abs(fft(x))/N; x_b = x.*bartlett(N)'; xf_b = abs(fft(x_b))/N;
3. Using the Bartlett window figure(1) subplot(2,2,1);plot(index_t,x);grid xlabel('Time index n'); ylabel('x(n)'); subplot(2,2,3); plot(index_t,x_b);grid; xlabel('Time index n'); ylabel('Triangular windowed x(n)'); subplot(2,2,2);plot(f,xf);grid;axis([0 8000 0 1]); xlabel('Frequency (Hz)'); ylabel('Ak (no window)'); subplot(2,2,4); plot(f,xf_b);grid; axis([0 8000 0 1]); xlabel('Frequency (Hz)'); ylabel('Triangular windowed Ak');
8/14/2019 Lab 6 DFT
8/10
b.1. Generate the sine wave sequence x = 2* sin (2000*pi*[0: 1: 100]*T);
2. Apply the FFT algorithm N=length(x); index_t = [0: 1: N - 1]; f = [0: 1: N - 1]*fs/N; xf = abs(fft(x))/N; x_hm = x.*hamming(N)'; xf_hm=abs(fft(x_hm))/N;
3. Using the Hamming window figure(2) subplot(2,2,1);plot(index_t,x);grid xlabel('Time index n'); ylabel('x(n)'); subplot(2,2,3); plot(index_t,x_hm);grid xlabel('Time index n'); ylabel('Hamming windowed x(n)'); subplot(2,2,2);plot(f,xf);grid;axis([0 fs 0 1]); xlabel('Frequency (Hz)'); ylabel('Ak (no window)'); subplot(2,2,4); plot(f,xf_hm);grid;axis([0 fs 0 1]); xlabel('Frequency (Hz)'); ylabel('Hamming windowed Ak');
0 50 100-2
-1
0
1
2
Time index n
x(n)
0 50 100-2
-1
0
1
2
Time index n
Hammingwindowedx(
n)
0 2000 4000 6000 80000
0.5
1
Frequency (Hz)
Ak(nowindow)
0 2000 4000 6000 80000
0.5
1
Frequency (Hz)
HammingwindowedA
k
8/14/2019 Lab 6 DFT
9/10
c.1. Generate the sine wave sequence x = 2* sin (2000*pi*[0: 1: 150]*T);
2. Apply the FFT algorithm N=length(x); index_t = [0: 1: N - 1]; f = [0: 1: N - 1]*fs/N; xf = 2*abs(fft(x))/N;xf(1) = xf(1)/2; x_hn = x.*hanning(N)';; xf_hn=2*abs(fft(x_hn))/N;xf_hn(1)=xf_hn(1)/2;
3. Using the Hanning window figure(3) subplot(2,2,1);plot(index_t,x);grid xlabel('Time index n'); ylabel('x(n)'); subplot(2,2,3); plot(index_t,x_hn);grid xlabel('Time index n'); ylabel('Hanning windowed x(n)'); subplot(2,2,2);plot(f(1:(N-1)/2),xf(1:(N-1)/2));grid;axis([0 fs/2 0 1]); xlabel('Frequency (Hz)'); ylabel('Ak (no window)'); subplot(2,2,4);plot(f(1:(N-1)/2),xf_hn(1:(N-1)/2));grid;axis([0 fs/2 0 1]); xlabel('Frequency (Hz)'); ylabel('Hanning windowed Ak');
Conclusion:
0 50 100 150-2
-1
0
1
2
Time index n
x(n)
0 50 100 150-2
-1
0
1
2
Time index n
Hanningwindowedx(n)
0 1000 2000 3000 40000
0.5
1
Frequency (Hz)
Ak(nowindow)
0 1000 2000 3000 40000
0.5
1
Frequency (Hz)
Hanningwind
owedAk
8/14/2019 Lab 6 DFT
10/10