P. 1
Matlab Filter Design

Matlab Filter Design

|Views: 420|Likes:
Published by Ng Tze Jia

More info:

Published by: Ng Tze Jia on Nov 01, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less





The purpose of this project is to design the filter using MATLAB to filter this signal below

The task to complete this project is:  1. Generate the signal above using Matlab. 2. Plot the DFT of this signal. 3. Design a digital Butterworth LPF to remove all frequencies except 1000 Hz. 4. Design a digital Chebyshev HPF filter to maintain only the 5000Hz frequency. 5. Design a BPF of your choice to remove all frequencies except 3000Hz.

From the signal given, the maximum frequency is 5000Hz In order to take the sample of the signal and to avoid aliasing, the sample frequency selected is

Fs 2FN = 15000Hz

The sample time will be 1/Fs = 0.0067ms The sample for 0 t 10ms is N = 10ms/Ts = 150 samples


Generate x(t) in MATLAB a) MATLAB code Compute figure 2 Compute figure 3 b) Output waveform Figure 1: signal x(t) Figure 1 : Signal Corrupted with Zero-Mean Random Noise of x(t) Figure 2 : Single-Sided Amplitude Spectrum of x(t) 2 .1.

the x[n] will be transform into Fourier transform which is X(w) before transform to DFT of X(k). After that. we need to transform the signal into discrete time signal . L = N-1 = 149.2) Plot the DFT of x(t) Basically. a) MATLAB code Show value of X[k] from k=0 to 149 b) Output waveform Figure 4 Magnitude of X[k] Figure 5 Phase of X[k] 3 . x(t). The X(k) value was compute with the length of N-1 which N is the number of sample from X(w). to compute the DFT of a time signal. x[n]. For this signal.

0232i 0.0427 + 0.0385 .0.0203i 0.0106i 0.0353 + 0.1175 ..0264i .0.0049i -0.0204 + 0.0.0015i k 21 22 23 24 25 26 27 28 29 30 .0.0565 .0.0330 ..0016i .0295 .0968i 0.0132i -0.1.0301 + 0.0385 + 0.0039i 0.0196i -0.0049i -0.0042i 0.0196i k 11 12 13 14 15 16 17 18 19 20 value 3.0012i 0.0176i 0.0356 + 0.0227 + 0.0.0542 . value 0.0188i 0.0152i 0.1710 .0485 + 0.0.0125i 0.0.0427 .0.0902 .0086i -0.c) Value of X[k] k 0 1 2 3 4 5 6 7 8 9 10 value 1.0313 + 0.0623 .0480 .0.0129i 0.0469i 0.0084i 0.0326 + 0.0107i -0.0032i -0.0.0293 -0.3217 .0299 + 0.0107i -0.0.0286i 0.0250 + 0.0330 + 0.0.0301 .0.0067i -0.0086i -0.0032i -0.0e+002 -0.0160i -0.0.0067i -0.0.0313 .0735 .0.0079i 0.0180 + 0. k 141 142 143 144 145 146 147 148 149 value -0.4894 .0485 .0062i 0.0353 .0.1269i 0.0154 + 0.0390 + 0.0132i -0.0274 + 0.0160i -0.0565 + 0.0295 + 0.0431 + 0.0016i 4 .

After the value of n an Wn has been obtained. In this MATLAB. we need to find the cutoff frequency of the filter by referring to its ideal design. After that. the function butter(for butterworth) and cheby1(fo chebyshev type I) will create the filter equation based on the information found in previous step. the function that was provided such as buttord(for butterworth) and cheb1ord(for chebyshev type I) will find the value of order. Wn for the filter with the given passband frequency. highpass or bandpass . 5 . the original signal. h[n] to obtain the output signal. The first step to design a filter is to determine the filter s type whether it is lowpass . y[n]. there is several basic information that needs to be focus. stopband frequency and sample frequency.FILTER DESIGNING APPROACH To design the filter. x(t) will be convolved with filter signal. To validate that the filter designed is correct. The design may consist of analog domain filter or digital domain filter. The magnitude spectrum of the output signal will validate whether the filter has function as it s needed or not.n and cut off frequency.

[sos.stem(t. Wn [n wn]=buttord(Wp.x1.Rs) [b a]=butter(n. x3=.stem(t. Wn is. n and the new cutoff frequency Wn %Converts a discrete-time zero-pole-gain representation of a given digital %filter to an equivalent second-order section representation. subplot(514). n and the new cutoff frequency.x3).'r').'r').'low').g]=zp2sos(z.Rp.title('Butterworth lowpass Filter') fvtool(y). we need to determine the cutoff frequency which is 1000Hz So the pass band will be. x2=2*cos(2*pi*f2*t).plot(t.1398 a) MATLAB code close all.hold on. figure(1). Rp = 3.x2. the order. %Passing signal through filter %plotting %magnitude and phase response fvtool(Hd).Xw.title('Frequency domain Filtered Y'). second-order section.title('X1+X2+X3=5cos(2*pi*1000*t)+2cos(2*pi*3000*t)+0. subplot(515). Determine order.hold on.y). Ws = 2000/7500.plot(t.f2=3000. n = 10 and Wn = 0.p. To design this filter. clear all.x3.plot(t.'r').y. direct-form II filter Hd = dfilt. 6 .hold on.5cos(2*pi*5000*t)').hold on.'r').fs=15000. %butterworth lowpass Filter Wp = 1000/7500. in decibels %Returns the lowest order n of the butterworth filter.plot(t.hold on. title('filter signal').5cos(2*pi*5000*t)').'low') [z. subplot(513).3) Design a digital Butterworth LPF to remove all frequencies except 1000 Hz.title('Original X1=5cos(2*pi*1000*t)').Xw).f3=5000.wn.plot(t.x1). Rs = 60. t=0:1/fs:. subplot(512).k]= butter(n.x2). %Discrete-time.g).wn. Xw=x1+x2+x3.k). in decibels %Stopband attenuation. Wp = 1000/7500 and the stopband is Ws = 2000/7500 The filter contain less than 3dB ripple in the pass band and 60dB of attenuation in the stopband From the code generated.p.5*cos(2*pi*f3*t).stem(t.stem(t.title('Filtered Y signal').title('Original X2=2cos(2*pi*3000*t)').01.'r').stem(t. %original signal x1=5*cos(2*pi*f1*t).Ws. f1=1000. y=filter(Hd. Show filter window tool %Time Domain subplot(511). %Passband corner frequency %Stopband corner frequency %Passband ripple.df2sos(sos.title('Original X3=0. %and the corresponding cutoff frequencies. plot([b a]).Xw).

b) Output waveform Figure 6 : magnitude response of filter Figure 7 : phase response of filter 7 .

Figure 8 : signal of the filter c) Filter validation Figure 9: Shows that the filtered signal is almost the same with X1 signal with 1000Hz and magnitude of 5 which means that X2 and X3 is being filtered. 8 .

lpf). res=2*pi/360.Alternative method: To validate the filter that have been designed. x(t) was convolved with the filter. lpf=[b a] out=conv(x. Figure 10: output signal after filtered Figure 11: magnitude spectrum of the filtered signal From figure 11. figure(2). h[n] using the MATLAB code as below. 9 .out_mag(1:75)) [b a] Is the filter equation The output waveform after the signal has been filtered out is.plot(w(1:75). x=5*cos(2*pi*f1*ts)+2*cos(2*pi*f2*ts)+0.5*cos(2*pi*f3*ts). w=0:res:2*pi-res. figure(1). it shows that the frequency at 1000Hz is remain and proved that this filter is valid.plot(out) out_mag=abs(out).*15000/(2*pi). ts=0:1:100. the input signal.

'r').Rp.x1). Xw=x1+x2+x3.plot(t. %Chebyshev Type 1 highpass Filter Wp = 5000/7500.title('Filtered Y signal'). in decibels Rs = 40.Xw).Xw).k]= cheby1(n.x2.title('Chebyshev Type I Highpass Filter') fvtool(x1).stem(t. %Passing signal through filter %Plotting %Frequency Domain fvtool(Hd).5cos(2*pi*5000*t)'). to get the frequency at 5000Hz only The band pass frequency. fvtool(Xw). Wp = 5000/7500 Stop band frequency. direct-form II filter Hd = dfilt.title('Original X2=2*cos(2*pi*3000*t)').title('Original X3=0. the bandpass and stoppass band was first determined.plot(t.title('Frequency domain X1'). ripple at pass band is 3dB and Rs.plot(t.x3.5*cos(2*pi*f3*t).x2). second-order section.p.4) Design a digital Chebyshev HPF filter to maintain only the 5000Hz frequency. t=0:1/fs:.title('Frequency domain X2'). %Passband corner frequency %Stopband corner frequency Ws = 4500/7500.fs=15000.hold on.a] = cheby1(n.'high').stem(t. Ws = 4000/7500 The Rp.title('Frequency domain X1+X2+X3'). [sos. x3=.Rp. subplot(514). f1=1000.y). Rp = 3.01.title('Frequency domain X3').g]=zp2sos(z. [z.Wn.stem(t. %Passband ripple. fvtool(x3). %Discrete-time.Wn. in decibels %Returns the lowest order n of the Chebyshev type I filter.f3=5000. subplot(515). subplot(513). %original signal x1=5*cos(2*pi*f1*t).'high'). ripple at stop band is 40dB The order. Wn [n. y=filter(Hd.'r').x3).'r'). Cheby1 indicate that 1 order chebyshev is used st 10 .Xw. x2=2*cos(2*pi*f2*t). [b.title('Frequency domain Filtered Y').hold on.g).hold on. fvtool(y).plot(t.f2=3000. %Converts a discrete-time zero-pole-gain representation of a given digital %filter to an equivalent second-order section representation. %Time Domain subplot(511).k).Rs).6667 a) MATLAB code close all.hold on. fvtool(x2).df2sos(sos.'r'). %Stopband attenuation.Rp.title('Original X1=5*cos(2*pi*1000*t)').5*cos(2*pi*5000*t)').title('X1+X2+X3=5cos(2*pi*1000*t)+2cos(2*pi*3000*t)+0.plot(t.stem(t. %and the corresponding cutoff frequencies.hold on.stem(t. n and the new cutoff frequency is: n= 6 and Wn = 0.p.Ws.Wn] = cheb1ord(Wp. clear all. subplot(512).'r').y.x1. In order to design the HPF.

b) Output waveform Figure 12: magnitude response Figure 13: phase response 11 .

12 .c) Filter validation: Figure 14: the magnitude and phase response of the filtered signal.5 which means that X1 and X2 is being filtered. Figure 15: the filtered signal is almost the same with X3 signal with 5000Hz and magnitude of 0.

Ws. the passband needed is from 3000Hz to 3500Hz and the stop band is 500Hz different before and after the pass band.p. title('filter signal').title('Original X3=0. %Converts a discrete-time zero-pole-gain representation of a given digital %filter to an equivalent second-order section representation. %Passband corner frequency %Stopband corner frequency %Passband ripple.hold on. [sos. clear all. %Passing signal through filter y=filter(Hd.'r').Rs) [b a]=butter(n.title('Filtered Y signal'). %plotting %magnitude and phase response fvtool(Hd). subplot(515).k]= butter(n. %butterworth Bandpass Filter Wp = [3000 3500]/7500.'r'). ripple at the pass band is 3dB and the ripple at stop band is 80dB a) MATLAB code close all.stem(t.plot(t. t=0:1/fs:.wn) [z.'r').g]=zp2sos(z.x3).x2). the order. Rs = 80. subplot(512).plot(t.title('Butterworth bandpass Filter') fvtool(y). second-order section. in decibels %Returns the lowest order n of the butterworth filter.y).plot(t. figure(1). Wn is.01.title('Frequency domain Filtered Y').stem(t.Xw. plot([b a]).3975 0.title('Original X1=5cos(2*pi*1000*t)').hold on.stem(t.f2=3000.stem(t.df2sos(sos.5) Design a BPF of butterworth filter to remove all frequencies except 3000Hz To design this filter so that only 3000Hz frequency remains.title('Original X2=2cos(2*pi*3000*t)').Rp.x3.title('X1+X2+X3=5cos(2*pi*1000*t)+2cos(2*pi*3000*t)+0. %original signal x1=5*cos(2*pi*f1*t). x3=. Xw=x1+x2+x3. direct-form II filter Hd = dfilt.f3=5000.p. subplot(514).4693] The Rp.x2.Xw). Rp = 3.plot(t.hold on.k). n and new cutoff frequency. Ws = [2500 4000]/7500. %Discrete-time. %and the corresponding cutoff frequencies.fs=15000.g). in decibels %Stopband attenuation. f1=1000.x1.Xw). x2=2*cos(2*pi*f2*t).'r'). From the MATLAB code generates.5*cos(2*pi*f3*t).5cos(2*pi*5000*t)'). 13 .y.wn). Wn [n wn]=buttord(Wp.x1).5cos(2*pi*5000*t)').hold on. n = 9 and Wn = [0.hold on. subplot(513).stem(t.'r'). %Time Domain subplot(511).plot(t.

b) Output waveform Figure 16: magnitude response Figure 17: phase response 14 .

c) Filter validation Figure 18: filter signal Figure 19: the filtered signal is almost the same with X2 signal with 3000Hz and magnitude of 2 which means that X1 and X3 is being filtered. 15 .

res=2*pi/120. figure(1). Figure 20: output signal after filtered Figure 21: magnitude spectrum of the signal From figure 21.*15000/(2*pi). the same approach is use by using the same MATLAB code as below.plot(out) out_mag=abs(out). ts=0:1:100.5*cos(2*pi*5000/15000*ts). w=0:res:2*pi-res.Alternative method: To validate the filter designed. figure(2).bpf).plot(w(1:75). x=5*cos(2*pi*1000/15000*ts)+2*cos(2*pi*3000/15000*ts)+0.out_mag(1:75)) The output waveform for the signal that has been filtered out is. bpf=[b a] out=conv(x. it shows that the frequency at 3000Hz remains and other frequency were eliminated 16 .

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->