Assignment 2

advertisement
Elec 484
Audio Signal Processing
Assignment 2
Steven Walker
0424415
Phase 1
1.
2.
From part 1 a is found to be 0.9615
3.
>> f=[0:5:4000];% freq from 0-4000Hz with 5Hz increments
>> fs=8000;%sample freq
>> f1=2000;%center freq
>> w=2*pi*f/fs;
>> z=exp(w*j);
>> B=100;
>> H=(0.0378*(z.*z-1))./(z.*z+(0.9615*.9615));%transfer function
>> figure %create figure
>> subplot(2,1,2), plot(f,angle(H))%phase response
>> xlabel('f[Hz]')
>> ylabel('Theta[rad]')
>> subplot(2,1,1), plot(f,abs(H))%plot mag response
>> title('Mag Response of H(z)')
>> xlabel('f[Hz]')
>> ylabel('H(z)')
Mag Response of H(z)
1.5
H(z)
1
0.5
0
0
500
1000
1500
2000
f[Hz]
2500
3000
3500
4000
0
500
1000
1500
2000
f[Hz]
2500
3000
3500
4000
Theta[rad]
2
1
0
-1
-2
From the figure the phase shift at f1 is found to be 1.56e-15
And the phase shift at f1+B/2 is -0.786.
The following plot was found using POI:
The result from POI is very close to the results from the plots done in Matlab.
4.
The frequency resolution is found using fs/N=7.8125Hz
The following code was written to perform the IDFT:
N=1024;
fs=8000; %sample freq
t=1;
f = linspace(0,fs,N);
fsize = size(f);
w=2*pi*f/fs;
wsize = size(w);
z=exp(w*j);
zsize = size(z);
H=(0.0378*(z.*z-1)./(z.*z+0.9245)); %TF from part 1&2
Hsize = size(H);
for n=1:1:N,
h(n)=0;
for k=1:1:N,
h(n)=H(k)*exp(j*2*pi*(n-1)*(k-1)/N)+h(n);
end
h(n)=h(n)*1/N;
end
real(h(1:25))%takes real part of the solution
For ifft:
>>x=ifft(H,N);
>> real(x(1:25))
The above matlab commands yield the following:
Every second term should be zero, this error is likely due to rounding in the transfer function
N
IDFT
FFT
0
0.0378
0.0378
1 -0.0001 -0.0001
2 -0.0727 -0.0727
3
0.0003
0.0003
4
0.0672
0.0672
5 -0.0005 -0.0005
6 -0.0621 -0.0621
7
0.0006
0.0006
8
0.0574
0.0574
9
-0.008
-0.008
10 -0.0531 -0.0531
11
0.0009
0.0009
12
0.0491
0.0491
13 -0.0009 -0.0009
14 -0.0453 -0.0453
15
0.001
0.001
16
0.0419
0.0419
17
-0.001
-0.001
18 -0.0387 -0.0387
19
0.0011
0.0011
20
0.0358
0.0358
21 -0.0011 -0.0011
22 -0.0331 -0.0331
23
0.0011
0.0011
24
0.0306
0.0306
5.
6.
The following Matlab code was implemented:
N = 1024;
n = [0:N-1]';
k = n;
b = [0.037855 0 -0.037855];
a = [1 0 0.92429];
hf = zeros(N,1);
[hf1,W] = freqz(b,a,N/2+1);
hf(1:N/2+1)= hf1;
hf(N/2+2:N) = conj(flipud(hf1(2:N/2)));
En = ones(N,1)*exp(-j*2*pi*n/N)';
K = k*ones(1,N);
Ekn = 1/N*En.^K;
hk = real(Ekn*hf)
This code as well as the method of using the spreadsheet to determine the impulse
response.
N
x[n]
0
1
2
1
0
0
From
Matlab
0.0379
-0.0002
-0.073
From
Spreadsheet
0.037855
0
-0.0728
% error
-0.11887
-0.27473
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
7.
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0.0007
0.0674
-0.001
-0.0623
0.0013
0.0576
-0.0015
-0.0532
0.0017
0.0492
-0.0019
-0.0454
0.002
0.042
-0.0021
-0.0388
0.0022
0.0358
-0.0022
-0.0331
0.0023
0.0306
-0.0023
0
0.06733
0
-0.0223
0
0.05752
0
-0.053165
0
0.04914
0
-0.04542
0
0.04198
0
-0.0388
0
0.03587
0
-0.03316
0
0.03066
0
-0.10397
-179.372
-0.13908
-0.06583
-0.1221
0.044033
-0.04764
0
0.195149
0.180941
0.195695
8.
n
IDFT
0
1
2
3
Matlab
0.0378
-0.0001
-0.0727
0.0003
0.0379
-0.0002
-0.073
0.0007
Partial Frac (1st
order)
0.0378
0
0.073
0
Partial Frac (2nd
order)
0.0378
0
-0.0727
0
9.
mag response of H(z)
1.5
H(z)
1
0.5
0
800
600
f[Hz]
phase response of H(z)
1000
1200
800
1000
1200
0
200
400
0
200
400
theta [rad]
2
0
-2
-4
600
f[Hz]
The matlab program for the above graphs is shown below:
N = 1024;
for r=1:1:N,
y(r)=0;
for n=1:1:N,
y(r)=h(n)*exp(-j*2*pi*(n-1)*(r-1)/N)+y(r); % Discrete Fourier Transform to get H(r)
end
end
% Plot H(r)
f = [1:1:N];
figure
subplot(2,1,2), plot(f,angle(y))
title('phase response of H(z)')
ylabel('theta [rad]')
xlabel('f[Hz]')
subplot(2,1,1), plot(f,abs(y))
title('mag response of H(z)')
ylabel('H(z)')
xlabel('f[Hz]')
10.
The following is matlab was used to create the graph:
y(n) and x(n)
H(z)
a=[1 0 0.9245];
b=[0.0378 0 -0.0378];
fs=8000;%sample freq
f=2000;%center freq
w=2*pi*f*(1/fs:1/fs:70/fs);
x=sin(w);
y=filter(b,a,x);
w=2*pi*f*(1/fs:1/fs:70/fs);
mag response of H(z)
x=sin(w);
1.5
y=filter(b,a,x);
x=interp(x,16);
y=interp(y,16);
1
plot(y);
hold
plot(x,'r');
0.5
hold
title('Input&Output With fc=2KHz')
ylabel('x(n)
and y(n)')
0
0
200
400
600
800
1000
xlabel('f[Hz]')
f[Hz]
Input and Output Graphed With Fc=2KHz
2
1200
1
0
-1
-2
0
200
400
600
f [Hz]
800
1000
1200
For f+B/2 the f was changed in the matlab code from 2000 to 2050 the following is the
result:
0.5
0
0
200
0
200
400
600
800
1000
f[Hz]
Input and Output Graphed With Fc=2KHz
1200
y(n) and x(n)
2
1
0
-1
-2
400
600
f [Hz]
800
1000
1200
11.
convolution of h(n) and sin()
0.04
0.03
0.02
amplitude
0.01
0
-0.01
-0.02
-0.03
-0.04
0
200
400
600
800
h(n)*sin()
1000
1200
1400
Phase 3
The following matlab program was written to perform the wahwah effect on a white noise
file:
function n = wah()
xy = 0.8;
x = xy;
y = 0;
noise = wavread('whitenoise.wav');%retrieve white noise
noise = noise(1:47000);
num = [.2 0 .2];
count1 = 1;
while (count1 < 80)
x = x - 0.02;
y = xy^2 - x^2;
y = y^(0.5);
a = 2*x;
b = x*x + y*y;
den = [1 a b];
filtered = filter(num,den,noise);
count2 = 1;
while count2 < length(filtered)
output(count1,count2) = filtered(count2);
count2 = count2 + 1;
end
end
count2 = 1;
count3 = 1;
while(count2 < length(filtered))
count1 = 1;
while (count1 < 80) & (count2 < length(filtered))
count3 = 1;
while (count3 < 300) & (count2 < length(filtered))
wahhed(count2) = output(count1,count2);
count3 = count3 + 1;
count2 = count2 + 1;
end
count1 = count1 + 1;
end
count1 = 79;
while (count1 >= 1) & (count2 < length(filtered))
counter3 = 1;
while (count3 < 300) & (count2 < length(filtered))
wahhed(count2) = output(count1,count2);
count3 = count3 + 1;
count2 = count2 + 1;
end
count1 = count1 - 1;
end
end
wavwrite(wahhed,5000,'swalker_wah_wah_fin');
The output file of the matlab is posted on my website.
Download