Bartlett Window Using Matlab
Bartlett Window Using Matlab
AIM: To design an FIR filter using Bartlett window technique using MATLAB functions. THEORY: The N=point Bartlett window is given by
In the design of FIR filters using any window technique, the order can be calculated using the formula given by
where p is the passband ripple, s is the stopband ripple, fp is the passband frequency, fs is the stopband frequency and Fs is the sampling frequency. BARTLETTBartlett window: W = BARTLETT(N) returns the N-point Bartlett window. w = bartlett(L) returns an L-point Bartlett window in the column vector w, where L must be a positive integer. FIR1FIR filter designusingthe windowmethod: B = FIR1(N,Wn) designs an N'th order lowpass FIR digital filter and returns the filter coefficients in length N+1 vector B. The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. The filter B is real and has linear phase. The normalized gain of the filter at Wn is -6 dB. B = FIR1(N,Wn,'high') designs an N'th order highpass filter.You can also use B = FIR1(N,Wn,'low') to design a lowpass filter. If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter with passband W1 < W < W2. You can also specify B = FIR1(N,Wn,'bandpass'). If Wn = [W1 W2], B = FIR1(N,Wn,'stop') will design a bandstop filter. CEILRoundtowardsplus infinity. CEIL(X) rounds the elements of X to the nearest integers towards infinity.
MATLABCODE: %program for the design of FIR Low pass, High pass, Band pass and Band stop filters using Bartlett window clc;clear all;close all; format long rp=input('Enter the passband ripple'); rs=input('Enter the stopband ripple'); fp=input('Enter the passband frequency'); fs=input('Enter the stopband frequency'); f=input('Enter the sampling frequency'); wp=2*fp/f; ws=2*fs/f; num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); n1=n+1; if(rem(n,2)~=0) n1=n; n=n-1; end y=bartlett(n1); %LOW PASS FILTER b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,1),plot(o/pi,m); xlabel('Gain in dB--->'); ylabel('Normalised frequency--->'); title('LOW PASS FILTER'); %HIGH PASS FILTER b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256);
m=20*log10(abs(h)); subplot(2,2,2),plot(o/pi,m); xlabel('Gain in dB--->'); ylabel('Normalised frequency--->'); title('HIGH PASS FILTER'); %BAND PASS FILTER wn=[wp ws]; b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,3),plot(o/pi,m); xlabel('Gain in dB--->'); ylabel('Normalised frequency--->'); title('BAND PASS FILTER'); %BAND STOP FILTER b=fir1(n,wn,'stop',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,4),plot(o/pi,m); xlabel('Gain in dB--->'); ylabel('Normalised frequency--->'); title('BAND STOP FILTER');
SAMPLEINPUTS: Enter the pass band ripple.04 Enter the stop band ripple.02 Enter the pass band frequency 1500 Enter the stop band frequency 2000 Enter the sampling frequency 8000
OUTPUT:
RESULT:
An FIR filter was designed using Bartlett window technique by using MATLAB functions and the magnitude plots for low pass, high pass, band pass and band stop filters were obtained.