Professional Documents
Culture Documents
Homework 1
Homework 1
Question 1
For Question 1, I have declared an time and frequency array which have 301 elements:
1
2
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
7
8
9
10
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)
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)
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
Phase (degrees)
-100
-200
-300
-400
0
0.1
0.2
0.3
0.4
0.5
0.6
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
Phase (degrees)
50
0
-50
-100
-150
-200
0
0.1
0.2
0.3
0.4
0.5
0.6
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)