This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex04_p03.m
64 lines (59 loc) · 1.87 KB
/
ex04_p03.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
clc; clear; close all;
%% Problem 3
%% b)
poles = [2,-1.8];
zero_ub = [1.9,-1.9];
zero_lb = [0.1,0.1];
% Plot magnitude response of filters
[h_ub,w] = freqz(zero_ub,poles);
[h_lb,w] = freqz(zero_lb,poles);
figure(1); subplot(2,1,1);
plot(w,abs(h_ub)); axis([0,pi,0,1.5]); xlabel('Angular frequency'); ylabel('Magnitude response'); title('Magnitude response for the upper branch');
subplot(2,1,2);
plot(w,abs(h_lb)); axis([0,pi,0,1.5]); xlabel('Angular frequency'); ylabel('Magnitude response'); title('Magnitude response for the lower branch');
%%
% Upper branch -> high pass
% Lower branch -> low pass
%% c)
% Listen to original and modified Audio Sample
alpha=0.7;
K=3;
wavfile='Audio_Sample.wav';
[x,fs]=audioread(wavfile);
% Plot magnitude response for different alpha
figure(2);
hold on;
for alpha = [0.5 0.7 0.9];
B(1)= (K/2)*(1-alpha)+(1/2)*(1+alpha);
B(2)= (K/2)*(1-alpha)-(1/2)*(1+alpha);
A = [1, -alpha];
y = filter(B,A,x);
[H,W]=freqz(B,A,1024);
normFreq = [0:1/(length(H)-1):1];
plot(normFreq,(abs(real(H))));
title(['Frequency response',' K=',num2str(K)]);
xlabel('Normalized frequency'); ylabel('Magnitude');
end;
legend('alpha=0.5','alpha=0.7','alpha=0.9');
hold off;
% Plot magnitude response for different K
alpha=0.7;
figure(3);
hold on;
for K = [0.5 1 4];
B(1)= (K/2)*(1-alpha)+(1/2)*(1+alpha);
B(2)= (K/2)*(1-alpha)-(1/2)*(1+alpha);
A = [1, -alpha];
y = filter(B,A,x);
[H,W]=freqz(B,A,1024);
normFreq = [0:1/(length(H)-1):1];
plot(normFreq,(abs(real(H))));
title('Frequency response, alpha = 0.7');
xlabel('Normalized frequency'); ylabel('Magnitude');
end;
legend('K=0.5','K=1','K=4');
hold off;
%%
% K is the gain of the low-pass filter. Higher K gives more gain for the
% lower frequencies. Alpha controls the low-pass filter bandwidth or cutoff
% frequency. A high Alpha reduced the cut-off frequency and bandwidth.