Upload
alp
View
3
Download
0
Embed Size (px)
DESCRIPTION
Digital Signal processing Homework Bilkent
Citation preview
MATLAB Problem Set 1
Ali Alp STN21200685EEE424-1
October 25, 2015
Question 1
For Question 1, I have declared an time and frequency array which have 301 elements:
1 n = linspace(0,pi,301); %Decleration of frequency array from 0 to pi2 t = [0:1/300:1]; %Decleration of frequency array from 0 to 1 with 301 samples
Using these array, I have created cosinus using the matlab and I have plotted it by stem command. Asa result, the code for Question 1 is as below.
1 %% Question 12 n = linspace(0,pi,301); %Decleration of frequency array from 0 to pi3 t = [0:1/300:1]; %Decleration of frequency array from 0 to 1 with 301 samples4 x1 = cos(2*pi*n.*t); %Cosine is created5 figure(1)6 stem(t,x1);7 xlabel('Time (t)');8 ylabel('Amplitude (x[t])');9 title('Swept-Frequency Cosine');
According to this code, I have acquired this plot which is a swept-frequency cosine whose frequencyincreases from 0 to π.
Time (t)0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Am
plitu
de (
x[t])
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1Swept-Frequency Cosine
Figure 1: Plot for Question 1
A additional comment on Figure 1 is that the signal starts at 1 and finishes at 0. The reason is that wespecified our cosine to sample from 0 and end at π.
Question 2
In this question, our goal is to implement FIR and IIR filters;then, apply them to a specific signal. Theequation of filters are
FIR Filter:y[n] = 0.5x[n] + 0.27x[n1] + 0.77x[n2]
1
IIR Filter:y[n] = 0.45[n] + 0.5x[n1] + 0.45x[n2] + 0.53y[n− 1]0.46y[n2]
The input signal is
x[n] = cos
(20πn
256
)+ cos
(200πn
256
)2.a
First of all, I have created a cosine in the matlab according to the input. The filters are also declared byusing filter command after specifying the coefficients of the numerator and denominator.
1 t = 1:301;2 x = cos(20*pi.*t./256) + cos(200*pi.*t./256);3
4 b1 = [0.5 0.27 0.77]; %Numerator5 a1 = 1; %Denominator6 y1 = filter(b1,a1,x); %FIR Filter7
8 b2 = [0.45 0.5 0.45]; %Numerator9 a2 = [1 -0.53 0.46]; %Denominator
10 y2 = filter(b2,a2,x); %IIR Filter
2.b
The plot of the input and output signals of FIR and IIR filters are indicated below at Figure 2 and Figure3.
Time (t)0 50 100 150 200 250 300 350
Am
plitu
de (
x[t])
-2
-1
0
1
2Input Signal
Time (t)0 50 100 150 200 250 300 350
Am
plitu
de (
x[t])
-4
-2
0
2
4FIR Filtered Signal
Figure 2: Plot for Question 2b: FIR Signal Output
According to Figure 2, our signal, which is a corrupted cosine with noisy second cosine, is cleared by FIRfilter in some sense. The output of the FIR filter became more like a soft cosine; thus, it can implied that it isa low-pass filter.
IIR filter output is better than FIR and we can see such a soft cosine signal that is filtered from most ofthe noise of the input signal. These arguments are valid if we only consider the time domain outputs of filtersand it can be concluded in low-pass filtering. However, it is not true at all.
freqz command of matlab should also be considered to determine the characteristics of the filters. Usingcode freqz(b2,a2) a amplitude and phase response diagram pop-ups and indicates the responses. FIR filterresponse in Figure 4 indicates that it is likely a stop-band filter rather than a low-pass filter. The reasonwhy it eliminates the much of the noise of the input signal is, when a closer observation is done, the responseis soft and it acts similar to a low pass filter until 0.7×π radians.
2
Time (t)0 50 100 150 200 250 300 350
Am
plitu
de (
x[t])
-2
-1
0
1
2Input Signal
Time (t)0 50 100 150 200 250 300 350
Am
plitu
de (
x[t])
-2
-1
0
1
2IIR Filtered Signal
Figure 3: Plot for Question 2b: IIR Signal Output
For IIR filter, freqz command also clears that it is a notch filter rather than a low pass filter. If youkeep your attention to the input signal that its frequency is 200πn
256 which is around 0.7×π. The notch filteringis sharply around this frequency; therefore, a better noise elimination and acquiring the first cosine element ofthe input signal is achieved. The freqz command output can be seen in Figure 5
Normalized Frequency (×: rad/sample)0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Pha
se (
degr
ees)
-400
-300
-200
-100
0
Normalized Frequency (×: rad/sample)0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Mag
nitu
de (
dB)
-15
-10
-5
0
5FIR Filter
Figure 4: Plot for Question 2b: FIR Signal Response
Normalized Frequency (×: rad/sample)0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Pha
se (
degr
ees)
-200
-150
-100
-50
0
50
Normalized Frequency (×: rad/sample)0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Mag
nitu
de (
dB)
-150
-100
-50
0
50IIR Filter
Figure 5: Plot for Question 2b: IIR Signal Response
2.c
When the first input signal that is generated at Question 1 is used for filtering the output plot is shown atFigure 6. It should be remark that this signal at Figure 6 is frequency increasing; thus, in FIR filter, the higher
3
Time (t)0 50 100 150 200 250 300 350
Am
plitu
de (
x[t])
-1
-0.5
0
0.5
1Original Signal
Time (t)0 50 100 150 200 250 300 350
Am
plitu
de (
x[t])
-2
-1
0
1
2FIR Filtered Signal
Time (t)0 50 100 150 200 250 300 350
Am
plitu
de (
x[t])
-2
-1
0
1
2IIR Filtered Signal
Figure 6: Plot for Question 2b: IIR Signal Response
frequency contents are more attenuated. The same manner occurs here that FIR acts like a low-pass filter dueto FIR’s sharp response. In IIR filter, we can hardly observe low-pass filtering since its response is sharp. Only0.7×π frequency content of input signal is attenuated when it is filtered by IIR signal, where we can seem toobserve this phenomenon at around 300 t.
4