Sunteți pe pagina 1din 5

MATLAB Problem Set 1

Ali Alp STN


21200685
EEE424-1
October 25, 2015

Question 1
For Question 1, I have declared an time and frequency array which have 301 elements:
1
2

n = linspace(0,pi,301); %Decleration of frequency array from 0 to pi


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. As
a result, the code for Question 1 is as below.
1
2
3
4
5
6
7
8
9

%% Question 1
n = linspace(0,pi,301); %Decleration of frequency array from 0 to pi
t = [0:1/300:1];
%Decleration of frequency array from 0 to 1 with 301 samples
x1 = cos(2*pi*n.*t); %Cosine is created
figure(1)
stem(t,x1);
xlabel('Time (t)');
ylabel('Amplitude (x[t])');
title('Swept-Frequency Cosine');

According to this code, I have acquired this plot which is a swept-frequency cosine whose frequency
increases from 0 to .

Swept-Frequency Cosine

1
0.8
0.6

Amplitude (x[t])

0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

Time (t)
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 we
specified 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. The
equation 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

20n
256

(
+ cos

200n
256

2.a
First of all, I have created a cosine in the matlab according to the input. The filters are also declared by
using filter command after specifying the coecients of the numerator and denominator.
1
2

t = 1:301;
x = cos(20*pi.*t./256) + cos(200*pi.*t./256);

3
4
5
6

b1 = [0.5 0.27 0.77]; %Numerator


a1 = 1;
%Denominator
y1 = filter(b1,a1,x); %FIR Filter

7
8
9
10

b2 = [0.45 0.5 0.45]; %Numerator


a2 = [1 -0.53 0.46]; %Denominator
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 Figure
3.
Input Signal

Amplitude (x[t])

2
1
0
-1
-2
0

50

100

200

250

300

350

250

300

350

Time (t)
FIR Filtered Signal

Amplitude (x[t])

150

2
0
-2
-4
0

50

100

150

200

Time (t)

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 FIR
filter in some sense. The output of the FIR filter became more like a soft cosine; thus, it can implied that it is
a low-pass filter.
IIR filter output is better than FIR and we can see such a soft cosine signal that is filtered from most of
the noise of the input signal. These arguments are valid if we only consider the time domain outputs of filters
and 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. Using
code freqz(b2,a2) a amplitude and phase response diagram pop-ups and indicates the responses. FIR filter
response in Figure 4 indicates that it is likely a stop-band filter rather than a low-pass filter. The reason
why it eliminates the much of the noise of the input signal is, when a closer observation is done, the response
is soft and it acts similar to a low pass filter until 0.7 radians.
2

Input Signal

Amplitude (x[t])

2
1
0
-1
-2
0

50

100

150

Amplitude (x[t])

200

250

300

350

200

250

300

350

Time (t)
IIR Filtered Signal

1
0
-1
-2
0

50

100

150

Time (t)

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 you
keep your attention to the input signal that its frequency is 200n
256 which is around 0.7. The notch filtering
is sharply around this frequency; therefore, a better noise elimination and acquiring the first cosine element of
the input signal is achieved. The freqz command output can be seen in Figure 5
FIR Filter

Magnitude (dB)

-5

-10

-15
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

0.7

0.8

0.9

Normalized Frequency (: rad/sample)

Phase (degrees)

-100

-200

-300

-400
0

0.1

0.2

0.3

0.4

0.5

0.6

Normalized Frequency (: rad/sample)

Figure 4: Plot for Question 2b: FIR Signal Response

IIR Filter

Magnitude (dB)

50

-50

-100

-150
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

0.7

0.8

0.9

Normalized Frequency (: rad/sample)

Phase (degrees)

50
0
-50
-100
-150
-200
0

0.1

0.2

0.3

0.4

0.5

0.6

Normalized Frequency (: rad/sample)

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 at
Figure 6. It should be remark that this signal at Figure 6 is frequency increasing; thus, in FIR filter, the higher
3

Original Signal

Amplitude (x[t])

1
0.5
0
-0.5
-1
0

50

100

150

Amplitude (x[t])

200

250

300

350

200

250

300

350

200

250

300

350

Time (t)
FIR Filtered Signal

1
0
-1
-2
0

50

100

150

Time (t)
IIR Filtered Signal

Amplitude (x[t])

2
1
0
-1
-2
0

50

100

150

Time (t)

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 due
to FIRs sharp response. In IIR filter, we can hardly observe low-pass filtering since its response is sharp. Only
0.7 frequency content of input signal is attenuated when it is filtered by IIR signal, where we can seem to
observe this phenomenon at around 300 t.

S-ar putea să vă placă și