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 ≥ 2F N = 15000Hz The sample time will be 1/Fs = 0.0067ms The sample for 0 ≤ t ≤ 10ms is N = 10ms/Ts = 150 samples 1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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
1
1. Generate x(t) in MATLAB
a) MATLAB code
b) Output waveform
2
Compute figure 2
Compute figure 3
Figure 2 : Signal Corrupted with Zero-Mean Random Noise of x(t)
Figure 1 : Single-Sided Amplitude Spectrum of x(t)
Figure 1: signal x(t)
2) Plot the DFT of x(t)
Basically, to compute the DFT of a time signal, x(t), we need to transform the signal into discrete
– time signal , x[n]. After that, the x[n] will be transform into Fourier transform which is X(w) before
transform to DFT of X(k). The X(k) value was compute with the length of N-1 which N is the number of
%butterworth lowpass FilterWp = 1000/7500; %Passband corner frequencyWs = 2000/7500; %Stopband corner frequency Rp = 3; %Passband ripple, in decibelsRs = 60; %Stopband attenuation, in decibels
%Returns the lowest order n of the butterworth filter,%and the corresponding cutoff frequencies, Wn[n wn]=buttord(Wp,Ws,Rp,Rs)[b a]=butter(n,wn,'low')[z,p,k]= butter(n,wn,'low');figure(1); plot([b a]); title('filter signal');
%Converts a discrete-time zero-pole-gain representation of a given digital%filter to an equivalent second-order section representation.[sos,g]=zp2sos(z,p,k);
%Discrete-time, second-order section, direct-form II filterHd = dfilt.df2sos(sos,g); y=filter(Hd,Xw); %Passing signal through filter
%plotting%magnitude and phase responsefvtool(Hd);title('Butterworth lowpass Filter')fvtool(y);title('Frequency domain Filtered Y');
Determine order, n and the new cutoff frequency Wn
Show filter window tool
b) Output waveform
7
Figure 6 : magnitude response of filter
8
Figure 7 : phase response of filter
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.
Alternative method:
To validate the filter that have been designed, the input signal, x(t) was convolved with the filter, h[n] using the MATLAB code as below;
%Chebyshev Type 1 highpass FilterWp = 5000/7500; %Passband corner frequencyWs = 4500/7500; %Stopband corner frequency Rp = 3; %Passband ripple, in decibelsRs = 40; %Stopband attenuation, in decibels
%Returns the lowest order n of the Chebyshev type I filter,%and the corresponding cutoff frequencies, Wn[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs); [b,a] = cheby1(n,Rp,Wn,'high');[z,p,k]= cheby1(n,Rp,Wn,'high');
%Converts a discrete-time zero-pole-gain representation of a given digital%filter to an equivalent second-order section representation.[sos,g]=zp2sos(z,p,k);
%Discrete-time, second-order section, direct-form II filterHd = dfilt.df2sos(sos,g); y=filter(Hd,Xw); %Passing signal through filter
%Plotting%Frequency Domainfvtool(Hd);title('Chebyshev Type I Highpass Filter')fvtool(x1);title('Frequency domain X1');fvtool(x2);title('Frequency domain X2');fvtool(x3);title('Frequency domain X3');fvtool(Xw);title('Frequency domain X1+X2+X3');fvtool(y);title('Frequency domain Filtered Y');
Figure 14: the magnitude and phase response of the filtered signal.
Figure 15: the filtered signal is almost the same with X3 signal with 5000Hz and magnitude of 0.5 which means that X1 and X2 is being filtered.
5) Design a BPF of butterworth filter to remove all frequencies except 3000Hz
13
To design this filter so that only 3000Hz frequency remains, the passband needed is from 3000Hz to
3500Hz and the stop band is 500Hz different before and after the pass band. From the MATLAB code
generates, the order, n and new cutoff frequency, Wn is;
n = 9 and Wn = [0.3975 0.4693]
The Rp, ripple at the pass band is 3dB and the ripple at stop band is 80dB
a) MATLAB code
14
close all;clear all;f1=1000;f2=3000;f3=5000;fs=15000;t=0:1/fs:.01; %original signalx1=5*cos(2*pi*f1*t); x2=2*cos(2*pi*f2*t); x3=.5*cos(2*pi*f3*t); Xw=x1+x2+x3; %butterworth Bandpass FilterWp = [3000 3500]/7500; %Passband corner frequencyWs = [2500 4000]/7500; %Stopband corner frequency Rp = 3; %Passband ripple, in decibelsRs = 80; %Stopband attenuation, in decibels %Returns the lowest order n of the butterworth filter,%and the corresponding cutoff frequencies, Wn[n wn]=buttord(Wp,Ws,Rp,Rs)[b a]=butter(n,wn)[z,p,k]= butter(n,wn);figure(1); plot([b a]); title('filter signal'); %Converts a discrete-time zero-pole-gain representation of a given digital%filter to an equivalent second-order section representation.[sos,g]=zp2sos(z,p,k); %Discrete-time, second-order section, direct-form II filterHd = dfilt.df2sos(sos,g); y=filter(Hd,Xw); %Passing signal through filter %plotting%magnitude and phase responsefvtool(Hd);title('Butterworth bandpass Filter')fvtool(y);title('Frequency domain Filtered Y'); %Time Domainsubplot(511);plot(t,x1,'r');hold on;stem(t,x1);title('Original X1=5cos(2*pi*1000*t)');subplot(512);plot(t,x2,'r');hold on;stem(t,x2);title('Original X2=2cos(2*pi*3000*t)');subplot(513);plot(t,x3,'r');hold on;stem(t,x3);title('Original X3=0.5cos(2*pi*5000*t)');subplot(514);plot(t,Xw,'r');hold on;stem(t,Xw);title('X1+X2+X3=5cos(2*pi*1000*t)+2cos(2*pi*3000*t)+0.5cos(2*pi*5000*t)');subplot(515);plot(t,y,'r');hold on;stem(t,y);title('Filtered Y signal');
b) Output waveform
15
Figure 16: magnitude response
Figure 17: phase response
c) Filter validation
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.
16
Figure 18: filter signal
Alternative method:
To validate the filter designed, the same approach is use by using the same MATLAB code as below;
The output waveform for the signal that has been filtered out is;
From figure 21, it shows that the frequency at 3000Hz remains and other frequency were eliminated
17
Figure 20: output signal after filtered Figure 21: magnitude spectrum of the signal