Sei sulla pagina 1di 9

ADVANCED COMMUNICATION LAB _#1

Q#1 Plot the following windows of FIR filter on the same plane and analyze it. Choose
appropriate parameters and use mat lab programming.

Hamming window
Hanning window
Rectangular window
Triangular window

%%q1 Plot the following windows of FIR filter on the same plane and analyze
it.
%%Choose appropriate parameters and use mat lab programming.
% for the following window type
%rectangular
%triangular
%hamming
%hanning
n=20; %Length of the window
fp=200; %passband frequency
fs=600; %stopband frequency
f=1000; % sampled frequency
wp=2*(fp/f); %passband edge frequency
ws=2*(fs/f); %stopband edge frequency
%wn=[wp,ws];
window=boxcar(n+1); %rectangular window
window1=hamming(n+1);
window2=hanning(n+1);
window3=bartlett(n+1); %triangular window
%window5=kaiser(n+1);
wn=2*(fp/f);
b=fir1(n,wn,window); %design by rectangular window
%b=Fir1(n,wn,'high',window);
[H,w]=freqz(b,1);
subplot(4,2,1);
plot(w/pi,20*log(abs(H)));
xlabel('nf');
ylabel('mag in dB');
title('rectangular magnitude response');
ADVANCED COMMUNICATION LAB _#1

subplot(4,2,2);
plot(w/pi,angle(H));
xlabel('nf');
ylabel('angle');
title('rectangular Angle response');
%%hamming
b1=fir1(n,wn,window1); %design by hamming window
[H1,w1]=freqz(b1,1);
subplot(4,2,3);
plot(w/pi,20*log(abs(H1)));
xlabel('nf');
ylabel('mag in dB');
title('hamming magnitude response');
subplot(4,2,4);
plot(w/pi,angle(H1));
xlabel('nf');
ylabel('angle');
title(' hamming Angle response');
% hanning
b2=fir1(n,wn,window2); %design by hanning window
[H2,w2]=freqz(b2,1);
subplot(4,2,5);
plot(w/pi,20*log(abs(H2)));
xlabel('nf');
ylabel('mag in dB');
title(' hanning magnitude response');
subplot(4,2,6);
plot(w/pi,angle(H2));
xlabel('nf');
ylabel('angle');
title(' hanning Angle response');
ADVANCED COMMUNICATION LAB _#1

% triangular
b3=fir1(n,wn,window3); %design by bartelet window
[H3,w3]=freqz(b3,1);
subplot(4,2,7);
plot(w/pi,20*log(abs(H3)));
xlabel('nf');
ylabel('mag in dB');
title(' trianguar magnitude response');
subplot(4,2,8);
plot(w/pi,angle(H3));
xlabel('nf');
ylabel('angle');
title(' triangular Angle response');
ADVANCED COMMUNICATION LAB _#1

Q#2 Design a 40th –order FIR band pass filter with pass band of 0.35<=w<=0.65.

A. What will happen when you decrease filter order to 10?


B. What are the filter coefficients for filter order 10?

%Design a 40th –order FIR band pass filter with pass band of 0.35<=w<=0.65.
% A) What will happen when you decrease filter order to 10?
% B) What are the filter coefficients for filter order 10?
N=40; % Order of the filter
wc1 =0.35; %lower cutoff frequency
wc2 = 0.65; %upper cutoff frequency
%wc1=input('Lower Cut off frequency:');
%wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];
h=fir1(N,wc,'bandpass');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter')

For filter order is N =40


ADVANCED COMMUNICATION LAB _#1

When filter order is N = 10


ADVANCED COMMUNICATION LAB _#1

Q#3 Design a 5-tap FIR band reject filter with a lower cut of frequency of 2,000Hz and an
upper cut of frequency of 2,400Hz and sampling rate of 8,000Hz using hamming window
method.

A. Determine the transfer function


B. Plot magnitude frequency response

% Design a 5-tap FIR band reject filter with a lower cut of frequency of 2,000Hz
% and an upper cut of frequency of 2,400Hz and sampling rate of 8,000Hz using
% hamming window method.
% A) Determine the transfer function
% B) Plot magnitude frequency response
%windows technique of Hanning using Band stop filter
[hz,w]=freqz([0.00748 0.00841 0.9 0.00841 0.00748], [1], 512); %transfer functi
phi=180*unwrap(angle(hz))/pi; % phase frequency response
subplot(2,1,1),
plot(w,20*log10(abs(hz))),
grid;
xlabel('Frequency (radians)');
ylabel('Magnitude Response (dB)')
subplot(2,1,2), plot(w, phi); grid;
xlabel('Frequency (radians)');
ylabel('Phase (degrees)');
ADVANCED COMMUNICATION LAB _#1

Q#4 Calculate the filter coefficients for a 3 tap fir low pass filter with a cut of frequency of 800Hz
and sampling rate of 8,000Hz using hamming window

A. determine the transfer function and difference equation of the designed fir system
B. Plot magnitude frequency response
%Calculate the filter coefficients for a 3 tap fir low pass filter with a cut
%of frequency of 800Hz and sampling rate of 8,000Hz using hamming window
% A) determine the transfer function and difference equation of the designed
%fir system
% B) Plot magnitude frequency response
[hz,w]= freqz([0.1871 0.2 0.187], [1], 512); % transfer function Cofficient
phi=180*unwrap(angle(hz))/pi; % finding phase response
subplot(2,1,1), plot(w,20*log10(abs(hz)));
grid;
xlabel('Frequency (radians)');
ylabel('Magnitude Response (dB)')
subplot(2,1,2), plot(w, phi); grid;
xlabel('Frequency (radians)');
ylabel('Phase (degrees)');
ADVANCED COMMUNICATION LAB _#1

NOISE CANCELATION SYSTEM


%**********NOISE CANCELATION FROM A SIGNAL ************
% DONE BY:-**** GEREMU TILAHUN ************************
% ID_______NO***RM7 448 *******************************
% original sine wave signal is generated and a random
% noisy signa is added final the noisy signal is filtered
Fs =500; %**sampling frequence of the signal
f=10; %** frequence of the signal
n = [1/Fs:1/Fs:1]; %range of the time axis
x=sin(2*pi*f*n); % the original signal
subplot(5,1,1);
plot(n,x);
%adding noise signal
y=rand(1,length(x)); % random noise signal
z=x+y; % adding the original signal with noisy one
subplot(5,1,2);
plot(n,z);
title('noisy signal');
xlabel('time');
ylabel('amplitude');
%spectral analaysis of the signal
L=length(z);
NEFT=2^nextpow2(L); %number of point
z_fft=abs(fft(z,NEFT)); %fast fourier transforming
%Creating frequency axis
freq=Fs/2*linspace(0,1,NEFT/2+1); %finging frequency responce
%PLOT SINGLE SIDEDAMPLITUDE
subplot(5,1,3);
plot(freq,z_fft(1:length(freq)));
title('single-sided amplitude spectrum of z(t)');
xlabel('frequency (Hz)');
% designing the filter
O = 1; % order of the signal
wn = [8 12]*2/Fs; % digital bandpass normalized frequency
[b,a] = butter(O,wn,'bandpass'); %
%frequency response of filter
%figure;
ADVANCED COMMUNICATION LAB _#1

%freqz(b,a,1024,Fs);
[h,w] = freqz(b,a,1024,Fs);
subplot(5,1,4);
plot(w,20*log10(abs(h)));
title('magnitude response of filter');
xlabel('frequency response');
ylabel('magnitude response');
grid on;
%filter the signal
z_filt =filter(b,a,z);
subplot(5,1,5);
plot(n,z_filt);
title('filtered signal');
xlabel('time');
ylabel('amplitude');

Potrebbero piacerti anche