You are on page 1of 19

09ece G ro u p 2

Vo Dinh Nhat Duong Nguyen Khanh Nam Tran Quang Nam

Lab Report EE 341 Lab 5: The FFT and Digital Filtering

Problem.1: MATLAB function FFT a) For f = 0.25


f = 0.25; n = 0:127; x = 1 + cos(2*pi*f*n); % Using abs command to obtain the magnitude of the complex valued sequence X = abs(fft(x)); plot(n,X); ylabel('Magnitude of FFT'); xlabel('k samples'); title('Unshifted DFT');

% Using fftshift command to obtain the spectrum plotted over the range X = fftshift(X); figure; plot(n,X); ylabel('Magnitude of FFT'); xlabel('k samples'); title('Shifted DFT');

% The number of points in FFT N = 128;

% Take the plot in hertz F = (-N/2:N/2-1)/(N/2); figure; plot(F,X); ylabel('Magnitude of FFT'); xlabel('Freq(Hz)'); title('Shifted DFT with a Hz frequency scale, Plotted in herts');

% Take the plot in normalized frequency F1 = (-N/2:N/2-1)/N; figure; plot(F1,X) ylabel('Magnitude of FFT'); xlabel('w(rad/s)'); title('Shifted DFT with a Hz frequency scale, Plotted in normalized frequency');

% Take the plot in radians F2 = (-N/2:N/2-1)*2*pi/N; figure; plot(F2,X); ylabel('Magnitude of FFT'); xlabel('w(rad/s)'); title('Shifted DFT with a Hz frequency scale, Plotted in radians');

Results:
For f=0.25
140 Unshifted DFT

120

100 Magnitude of FFT

80

60

40

20

20

40

60 80 k samples

100

120

140

Shifted DFT 140

120

100 Magnitude of FFT

80

60

40

20

20

40

60 80 k samples

100

120

140

Shifted DFT with a Hz frequency scale, Plotted in herts 140

120

100 Magnitude of FFT

80

60

40

20

0 -1

-0.8

-0.6

-0.4

-0.2

0 0.2 Freq(Hz)

0.4

0.6

0.8

Shifted DFT with a Hz frequency scale, Plotted in normalized frequency 140

120

100 Magnitude of FFT

80

60

40

20

0 -0.5

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

Shifted DFT with a Hz frequency scale, Plotted in radians 140

120

100 Magnitude of FFT

80

60

40

20

0 -4

-3

-2

-1

0 w(rad/s)

b) For f = 0.5 Results:

140

Unshifted DFT

120

100 Magnitude of FFT

80

60

40

20

20

40

60 80 k samples

100

120

140

Shifted DFT 140

120

100 Magnitude of FFT

80

60

40

20

20

40

60 80 k samples

100

120

140

140

Shifted DFT with a Hz frequency scale, Plotted in herts

120

100 Magnitude of FFT

80

60

40

20

0 -1

-0.8

-0.6

-0.4

-0.2

0 0.2 Freq(Hz)

0.4

0.6

0.8

Shifted DFT with a Hz frequency scale, Plotted in normalized frequency 140

120

100 Magnitude of FFT

80

60

40

20

0 -0.5

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

Shifted DFT with a Hz frequency scale, Plotted in radians 140

120

100 Magnitude of FFT

80

60

40

20

0 -4

-3

-2

-1

0 w(rad/s)

Comment:
As showed in the figures above, the frequency peak locations make sense because their peaks are at the point /2 and location where their corresponding frequencies are 0.25 and 0.5 respectively. There is also a peak for the constant part in the signal, that is, at = 0.

Problem.2 FrequencyShifting

%% Case 4: x[n] = sinc(f3*(n-32)).*(cos(2*pi*f3*n)) f3 = 0.4; x4 = sinc(f3*(n-32)).*(cos(2*pi*f3*n)); X4 = fft(x4); X4 = fftshift(X4); figure; subplot(2,1,1); plot(w,abs(X4)); title('x[n] = sinc(f3*(n-32)).*(cos(2*pi*f3*n))'); ylabel('Magnitude'); xlabel('w(rad/s)'); subplot(2,1,2); plot(w,angle(X4)); ylabel('Phase'); xlabel('w(rad/s)');

Results:
- Follow these figures are the type of each signal respectively:
n = 0:225; w = -0.5:(1/225):0.5; f1 = 0.15; x1 = sinc(f1*(n-32)); X1 = fft(x1); X1 = fftshift(X1);

a)
%% Case 1: x[n] = sinc(f(n-32)) subplot(2,1,1); plot(w,abs(X1)); title('x[n] = sinc(f(n-32))'); ylabel('Magnitude'); xlabel('w(rad/s)'); subplot(2,1,2); plot(w,angle(X1)); ylabel('Phase'); xlabel('w(rad/s)');

(a): x[n] = sinc(f(n-32)) 8 6 4 2 0 -0.5

Magnitude

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

4 2 Phase 0 -2 -4 -0.5

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

This signal is low-pass filter ( x[n]

= sinc(f(n-32)) ) .

b)
%% Case 2: x[n] = sinc(f(n-32)*(-1)^n) x2 = sinc(f1*(n-32)).*((-1).^n); X2 = fft(x2); X2= fftshift(X2); figure; subplot(2,1,1); plot(w,abs(X2)); title('x[n] = sinc(f(n-32)*(-1)^n)'); ylabel('Magnitude'); xlabel('w(rad/s)'); subplot(2,1,2); plot(w,angle(X2)); ylabel('Phase'); xlabel('w(rad/s)'

(b): x[n] = sinc(f(n-32)*(-1) ) 8 6 4 2 0 -0.5

Magnitude

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

4 2 Phase 0 -2 -4 -0.5

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

This signal is high-pass filter (x[n]

= sinc(f(n-32)*(-1)^n)).

c)
%% Case 3: x[n] = x1.*(cos(2*pi*f2*n)) f2 = 0.2; x3 = sinc(f1*(n32)).*(cos(2*pi*f2*n)); X3 = fft(x3); X3 = fftshift(X3); figure; subplot(2,1,1); plot(w,abs(X3)); title('x[n] = x1.*(cos(2*pi*f2*n))'); ylabel('Magnitude'); xlabel('w(rad/s)'); subplot(2,1,2); plot(w,angle(X3)); ylabel('Phase'); xlabel('w(rad/s)');

(c): x[n] = x1.*(cos(2*pi*f2*n)) 4 3 2 1 0 -0.5

Magnitude

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

4 2 Phase 0 -2 -4 -0.5

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

This signal is band-pass filter (x[n]

= x1.*(cos(2*pi*f2*n)) ).

d)
(d): x[n] = sinc(f3*(n-32)).*(cos(2*pi*f3*n)) 1.5

Magnitude

0.5

0 -0.5

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

4 2 Phase 0 -2 -4 -0.5

-0.4

-0.3

-0.2

-0.1

0 0.1 w(rad/s)

0.2

0.3

0.4

0.5

This signal is also band- pass filter (x[n]=sinc(f3*(n -32)).*(cos(2*pi*f3*n))).

Comment:
The signal x[n]=sinc(f3*(n -32)).*(cos(2*pi*f3*n)) in part (d) does not have a flat frequency response in the passband because DTFT of sinc function is rectangular perfectly when time indexes approach to infinity but this value cannot be found in MATLAB.

Prob.3FIR (Finite Impulse Response) Digital Filters


-Use the MATLAB function sptool to create a low pass FIR filter of order 10 (by playing around the pass-band and stop-band ripples specifications) with pass-band cutoff frequency of 0.3 and stop-band cutoff frequency of 0.4.

-Use frevalz01 to study the system. Turn in the frevalz01 plot of the system responses. >>frevalz01(Num,1);

Prob.4 IIR (Infinite Impulse Response) Digital Filters


-Use the MATLAB function butter to create a digital IIR low pass Butterworth filter with the same pass-band and stop-band cut-off frequency specifications as the FIR design in Question 3 and filter order of 10. >> [b,a] = butter(10,0.35) -Turn in the frevalz01 plot of the system responses. >>frevalz01 (b,a);

Compare the performance of this filter to that of the FIR filter: - The difference between FIR and IIR filters are the impulse response and phase response. - As figure show, the phase of IIR filters is difficult to control, no particular techniques available, while the phase of FIR Filters is linear and always possible. - From the figure, we can see that the magnitude response of a Butterworth filter decreases with frequency.

You might also like