Matlab Filter Design | Filter (Signal Processing) | Sampling (Signal Processing)

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(k) value was compute with the length of N-1 which N is the number of sample from X(w). For this signal. the x[n] will be transform into Fourier transform which is X(w) before transform to DFT of X(k). to compute the DFT of a time signal. L = N-1 = 149. x(t). we need to transform the signal into discrete time signal . 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 .2) Plot the DFT of x(t) Basically. After that. x[n].

0032i -0.0385 .0196i -0.0160i -0.0086i -0.0295 .0016i .0067i -0.0125i 0.1.0203i 0.0.0152i 0.0735 .0204 + 0.0264i .0084i 0.0129i 0.0.0016i 4 .0107i -0.0353 .0039i 0.0106i 0.0485 + 0.0469i 0.0485 .0.0062i 0.0390 + 0..0250 + 0.0301 + 0.0427 + 0.4894 .0299 + 0.0301 .3217 .0330 . k 141 142 143 144 145 146 147 148 149 value -0.0.0132i -0.0196i k 11 12 13 14 15 16 17 18 19 20 value 3.0.0160i -0.0107i -0.0274 + 0.0313 + 0.0353 + 0.0295 + 0.0032i -0.0042i 0.0227 + 0.0286i 0.0049i -0.0012i 0.0079i 0.0.0480 ..0313 .0232i 0.1175 .0188i 0.0067i -0.0.0330 + 0.0176i Value of X[k] k 0 1 2 3 4 5 6 7 8 9 10 value 1.0542 .0293 - -0.0.0623 .0154 + 0.0427 .0049i -0.0.0968i 0.1269i 0.0326 + 0.0086i -0.0e+002 -0.0180 + .0015i k 21 22 23 24 25 26 27 28 29 30 .0.0385 + 0.0356 + 0.1710 . value 0.0565 + 0.0431 + 0.0565 .0.

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

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

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 .

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

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

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

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

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

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

Sign up to vote on this title
UsefulNot useful