Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Question 4

FIR LOW PASS BLACK MAN FILTER

% read noise audio file


[yo,Fs]=wavread('severussnape_o.wav');
x_y=fft(yo);
no=length(x_y);
f = (0:no-1)/no*(Fs);
figure(1);
plot((1:no/2)/no*fs,abs(fyo(1:no/2)));
grid
wavplay (yo,Fs)
% read noise audio file
[yn,Fs]=wavread('severussnape_n.wav');
x_z=fft(yn);
no=length(x_z);
f = (0:no-1)/no*(Fs);
figure(2);
plot((1:no/2)/no*fs,abs(fyo(1:no/2)));
grid
wavplay (yn,Fs)

%Filter specification
fs=3000;
fp=4000;
deltap=0.1;
detlas=70;
% FIR filter design
N=264; % manual calculation
fc=(fs+fp)/2;
wc=fc/ft;%the value of wc
ft=48000; % ranging form 0 to 1

%FIR filtering process


a=fir1(N,wc,'high',blackman(N+1));
y= filter(a,1,yn);
yz=fft(y);
lenght_y=length(yz);
fy= (0:lenght_y-1)/lenght_y*(Fs);
figure(3);
plot((1:no/2)/no*fs,abs(fyo(1:no/2)));
title ('Noisy Signal in Frequency Domain');
xlabel ('Hz');
ylabel ('Magnitude');
grid;
figure(4);
freqz(a)

%play and write filtered signal


wavplay(y,Fs)
wavwrite(y,Fs,'FIR HIGH PASS BLACKMAN.wav')
IIR CHEBYSHEV2 HIGHPASS FILTER
% read noise audio file
[yo,Fs]=wavread('severussnape_o.wav');
x_y=fft(yo);
no=length(x_y);
f = (0:no-1)/no*(Fs);
figure(1);
plot((1:no/2)/no*fs,abs(fyo(1:no/2)));
grid
wavplay (yo,Fs)
% read noise audio file
[yn,Fs]=wavread('severussnape_n.wav');
x_z=fft(yn);
no=length(x_z);
f = (0:no-1)/no*(Fs);
figure(2);
plot((1:no/2)/no*fs,abs(fyo(1:no/2)));
grid
wavplay (yn,Fs)

%Filter parameter
fp = 3000;
fs = 4000;
ft = 48000;
Rp = 0.1;
Rs = 70;

%Filter design
Wp = 2*fp/ft;
Ws = 2*fs/ft;
%FIR filtering process
[n,Wp] = cheb2ord(Wp,Ws,Rp,Rs);
[b,a] = cheby2(n,Rp,Wp,'high');
y= filter(b,a,yn);
yz=fft(y);
no=length(yz);
fy= (0:no-1)/no*(Fs);
figure (3);
plot((1:no/2)/no*Fs,abs(fyo(1:no/2)));
title ('Filtered Signal in Frequency Domain');
xlabel ('Hz');
ylabel ('Magnitude');
grid;
figure(4);
freqz(b,a)

%play and write filtered signal


wavplay(y,Fs)
wavwrite(y,Fs,'IIR HIGH PASS cheby2.wav')

You might also like