ReportLab5 EE341 Group2
ReportLab5 EE341 Group2
ReportLab5 EE341 Group2
% 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');
% 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
80
60
40
20
20
40
60 80 k samples
100
120
140
120
80
60
40
20
20
40
60 80 k samples
100
120
140
120
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
120
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
120
80
60
40
20
0 -4
-3
-2
-1
0 w(rad/s)
140
Unshifted DFT
120
80
60
40
20
20
40
60 80 k samples
100
120
140
120
80
60
40
20
20
40
60 80 k samples
100
120
140
140
120
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
120
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
120
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)');
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
= 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)'
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
= 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)');
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
= 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
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.
-Use frevalz01 to study the system. Turn in the frevalz01 plot of the system responses. >>frevalz01(Num,1);
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.