ELEC484: Assignment 2 Andrew Nelder 04

ELEC484: Assignment 2
Andrew Nelder
04-22391
1.
2.
𝑓𝑠 = 8000 𝐻𝑧
𝑓𝑐 = 2000 𝐻𝑧
𝑓 = 4000 𝐻𝑧
2 βˆ— |1 βˆ’ π‘Ž|
βˆ†πœ” =
βˆšπ‘Ž
2πœ‹π΅
2πœ‹(100)
πœ‹
πœ”=
=
=
𝑓𝑠
8000
40
πœ‹
2 βˆ— (1 βˆ’ π‘Ÿ)
=
40
βˆšπ‘Ÿ
∴ |π‘Ÿ| = 0.9614
(𝑧 βˆ’ 1)(𝑧 + 1)
𝑧 2 + 0.9614
(𝑧 βˆ’ 1)(𝑧 + 1)
𝐻(𝑒 π‘—πœ” ) = 1 = 𝐾 βˆ— 2
𝑧 + 0.9245
∴ 𝐾 = 0.0193
𝐻(𝑧) = 𝐾 βˆ—
𝐻(𝑧) = 0.0378 βˆ—
(𝑧 βˆ’ 1)(𝑧 + 1)
𝑧 2 + 0.9245
ELEC484: Assignment 2
Andrew Nelder
04-22391
3. Could not use WinPOI software, as it does not display scale on the frequency response. Developed a
small matlab function instead.
fc=2000;
fs=8000;
f=[0:5:fs/2];
w=2*pi*f/fs;
z=exp(w*j);
B=100;
H=((0.0378*(z.*z-1))./(z.*z+0.9245));
figure
subplot(2,1,1), plot(f,abs(H))
title('Magnitude Response of H(z)')
ylabel('H(z)')
xlabel('f [Hz]')
subplot(2,1,2), plot(f,angle(H))
title('Phase Response of H(z)')
ylabel('Theta [rad]')
ELEC484: Assignment 2
Andrew Nelder
04-22391
xlabel('f [Hz]')
4. To complete this section. I used the following MatLab code.
f = [0:5:4000];
f0 = 2000;
fs = 8000;
w = (2*pi*f)/fs;
z = exp(w*j);
B = 100;
H = ((0.0378 * (z.*z-1))./(z.*z + 0.9245));
N = 801;
OUTPUT = 1:N;
for n = 0:1:(N-1)
OUTPUT(n+1) = 0;
for k = 0:1:(N-1)
OUTPUT(n+1) = OUTPUT(n+1) + H(k+1)*exp(((2*pi*i)/N)*k*n);
end
end
OUTPUT = (1/N)*OUTPUT;
O = real(OUTPUT);
Using Code Above:
Columns 1 through 8
Using Matlab Function (IFFT):
Columns 1 through 8
0.0378 -0.0726 0.0672 -0.0621 0.0574 0.0531 0.0491 -0.0454
0.0378 -0.0726 0.0672 -0.0621 0.0574 0.0531 0.0491 -0.0454
Columns 9 through 16
0.0420 -0.0388 0.0359 -0.0331 0.0306 0.0283 0.0262 -0.0242
Columns 17 through 24
0.0224 -0.0207 0.0191 -0.0177 0.0163 0.0151 0.0140 -0.0129
Columns 25 through 32
0.0119
Columns 9 through 16
0.0420 -0.0388 0.0359 -0.0331 0.0306 0.0283 0.0262 -0.0242
Columns 17 through 24
0.0224 -0.0207 0.0191 -0.0177 0.0163 0.0151 0.0140 -0.0129
Columns 25 through 32
0.0119
5.
π‘Œ(𝑧)
1 βˆ’ 𝑧 βˆ’2
= (0.0378) (
)
𝑋(𝑧)
1 + 0.9245βˆ’2
π‘Œ(𝑧) βˆ— (1 + 0.9245βˆ’2 ) = 𝑋(𝑧) βˆ— (1 βˆ’ 𝑧 βˆ’2 ) βˆ— (0.0378)
ELEC484: Assignment 2
Andrew Nelder
04-22391
π‘Œ(𝑧) + π‘Œ(𝑧) βˆ— (0.9245βˆ’2 ) = 𝑋(𝑧) βˆ— (0.0378) βˆ’ 𝑋(𝑧) βˆ— (0.0378) βˆ— 𝑧 βˆ’2
∴ 𝑦(𝑛) = 0.0378 βˆ— π‘₯(𝑛) βˆ’ 0.0378 βˆ— π‘₯(𝑛 βˆ’ 2) βˆ’ 0.9245 βˆ— 𝑦(𝑛 βˆ’ 2)
π‘Šπ‘–π‘›π‘ƒπ‘‚πΌ π‘†π‘œπ‘“π‘‘π‘€π‘Žπ‘Ÿπ‘’:
𝑦(𝑛) = π‘₯(𝑛) βˆ’ π‘₯(𝑛 βˆ’ 2) βˆ’ 0.9245 βˆ— 𝑦(𝑛 βˆ’ 2)
Note that the two are identical; however, one simply includes a unity gain of 1.
6.
n
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
h[n]
0.0379
-0.0002
-0.0729
0.0007
0.0673
-0.0010
-0.0623
0.0013
0.0575
-0.0015
-0.0532
0.0017
0.0491
-0.0019
-0.0454
0.0020
0.0420
-0.0021
-0.0388
0.0022
0.0358
-0.0022
-0.0331
0.0023
0.0306
ELEC484: Assignment 2
Andrew Nelder
04-22391
7.
8.
n
0
1
2
3
Section 6
0.0379
-0.0002
-0.0729
0.0007
Section 4
0.0379
-0.0002
-0.0729
0.0007
Partial Fractions
0.0378
-0.0002
-0.0728
0.0007
Long Division
0.0379
-0.0002
-0.0729
0.0007
ELEC484: Assignment 2
Andrew Nelder
04-22391
9.
N = 801;
for r=1:1:N,
y(r)=0;
for n=1:1:N,
y(r)=OUTPUT(n)*exp(-j*2*pi*(n-1)*(r-1)/N)+y(r);
h(n) to get H(r)
end
end
% Plot H(r) , which is y(r) above
f = [1:1:N];
figure
subplot(2,1,1), plot(f,abs(y))
title('Magnitude Response of H(z)')
ylabel('H(z)')
xlabel('f [Hz]')
% DFT of
ELEC484: Assignment 2
subplot(2,1,2), plot(f,angle(y))
title('Phase Response of H(z)')
ylabel('Theta [rad]')
xlabel('f [Hz]')
10.
Andrew Nelder
04-22391
ELEC484: Assignment 2
f_s = 8000;
f_0 = 2000;
%sampling frequency
%passband center frequency
b = [0.0378 0 -0.0378];
a = [1 0 0.9245];
%for f = f_0
t = 1/f_s:1/f_s:100/f_s;
w=2*pi*f_0*t;
x1 = sin(w);
y1 = filter(b,a,x1);
%plot stuff
t_i = 1/f_s:.1/f_s:100/f_s
xi = spline(t,x1,t_i);
yi = spline(t,y1,t_i);
Andrew Nelder
04-22391
ELEC484: Assignment 2
Andrew Nelder
04-22391
figure
plot(t,x1,'k x',t_i,xi,'k -',t,y1,'r x',t_i,yi,'r -')
AXIS([0 0.01 -1.25 1.25])
title('Sinusoid Response - - f=f_0. Input (black) / Output (red).')
ylabel('Magnitude')
xlabel('Time (s)')
%phase response for f=f_0
t_long = 1/f_s:1/f_s:100/f_s;
w_long=2*pi*f_0*t_long; % change value of f_0 to 2050Hz for part b.
x_long=sin(w_long);
y_long=filter(b,a,x_long);
p=y_long(:,100:150);
rot90(p);
[E,F]=max(p);
max_y_n=F+99;
y_long_max=y_long(:,max_y_n);
x_long_ymax=filter(b,a,x_long);
phi=asin(x_long_ymax);
phase_diff = phi-pi/2;
%time until steady state????
n_ss=find(y_long>y_long_max*0.99);
ss_time=(n_ss(1,1)-1)/f_s
ELEC484: Assignment 2
11.
f_s = 8000;
f_0 = 2000;
%sampling frequency
%passband center frequency
n=[0:1/f_s:1];
b = [0.0378 0 -0.0378];
a = [1 0 0.9245];
imp=zeros(1,100);
imp(1) = 1;
h=filter(b,a,imp);
x=sin(2*pi*f_0*n);
nn=n(1:80);
xx=x(1:80);
Andrew Nelder
04-22391
ELEC484: Assignment 2
Andrew Nelder
04-22391
y=conv(x,h);
yy=y(1:80);
t_i =[0:.1/f_s:80/f_s];
xi = spline(nn,xx,t_i);
yi = spline(nn,yy,t_i);
xxi=xi;
yyi=yi;
figure
plot(nn,xx,'k x',t_i,xi,'k -',nn,yy,'r x',t_i,yi,'r -')
AXIS([0 0.01 -1.25 1.25])
title('Sinusoid Response - - f=f_0. Input (black) / Output (red).')
ylabel('Magnitude')
xlabel('Time (s)')
x=sin(2*pi*(f_0+B/2)*n);
nn=n(1:80);
xx=x(1:80);
y=conv(x,h);
yy=y(1:80);
t_i =[0:.1/f_s:80/f_s];
xi = spline(nn,xx,t_i);
yi = spline(nn,yy,t_i);
xxi=xi;
yyi=yi;
figure
plot(nn,xx,'k x',t_i,xi,'k -',nn,yy,'r x',t_i,yi,'r -')
AXIS([0 0.008 -1.25 1.25])
title('Sinusoid Response - - f=f_0+B/2. Input (black) /
ylabel('Magnitude')
xlabel('Time (s)')
Output (red).')