SlideShare a Scribd company logo
1 of 14
Download to read offline
FILTER IMPLEMENTATION AND EVALUATION USING MATLAB
Our online Tutors are available 24*7 to provide Help with Filter Implementation and Evaluation
Homework/Assignment or a long term Graduate/Undergraduate Filter Implementation and
Evaluation Project. Our Tutors being experienced and proficient in Filter Implementation and
Evaluation ensure to provide high quality Filter Implementation and Evaluation Homework
Help. Upload your Filter Implementation and Evaluation Assignment at ‘Submit Your
Assignment’ button or email it to info@assignmentpedia.com. You can use our ‘Live Chat’
option to schedule an Online Tutoring session with our Filter Implementation and Evaluation
Tutors.
LOWPASS FIR FILTER
This example show how to design and implement an FIR filter using the command line
functions: fir1 and fdesign.lowpass, and the interactive tool fdatool.
To filter the input signal, these examples use the filter command. The examples in Zero-Phase
Filtering show you how to implement zero-phase filtering with filtfilt.
Create a signal to use in the examples. The signal is a 100-Hz sinewave in additive N(0,1/4)
white Gaussian noise. Set the random number generator to the default state for reproducible
results.
rng default;
Fs = 1000;
t = linspace(0,1,Fs);
x = cos
(2*pi*100*t)+0.5*randn(size(t));
The filter design is an FIR lowpass filter with order equal to 20 and a cutoff frequency of 150 Hz.
Use a Kasier window with length one sample greater than the filter order and β=3.
See kaiser for details on the Kaiser window.
Use fir1 to design the filter. fir1 requires normalized frequencies in the interval [0,1], where 1 is
(1)π radians/sample. To use fir1, you must convert all frequency specifications to normalized
frequencies.
Design the filter and view the filter's magnitude response.
fc = 150;
Wn = (2/Fs)*fc;
b = fir1(20,Wn,'low',kaiser(21,3));
fvtool(b,1,'Fs',Fs);
Apply the filter to the signal and plot the result for the first ten periods of the 100-Hz sinusoid.
y = filter(b,1,x);
plot(t(1:100),x(1:100),'k');
hold on;
plot(t(1:100),y(1:100),'r','linewidth',2);
legend('Original Signal','Filtered Data','Location','SouthEast');
xlabel('Seconds'); ylabel('Amplitude');
Design the same filter using fdesign.lowpass.
Set the filter specifications using the 'N,Fc' specification string. With fdesign.lowpass, you can
specify your filter design in Hz.
Fs = 1000;
d = fdesign.lowpass('N,Fc',20,150,Fs);
Hd = design(d,'window','Window',kaiser(21,3));
Filter the data and plot the result.
y1 = filter(Hd,x);
plot(t(1:100),x(1:100),'k');
hold on;
plot(t(1:100),y1(1:100),'r','linewidth',2);
legend('Original Signal','Filtered Data','Location','SouthEast');
xlabel('Seconds'); ylabel('Amplitude');
Design and implement a lowpass FIR filter using the window method with the interactive
tool fdatool.
Start FDATool by entering
fdatool
at the command line.
Set the Response Type to Lowpass. Set the Design Method to FIR and select
the Window method.
Under Filter Order, select Specify order. Set the order to 20.
Under Frequency Specifications. Set Units to Hz, Fs: to 1000, and Fc: to 150.
Click Design Filter.
Select File —>Export... to export your FIR filter to the MATLAB®
workspace as coefficients or a
filter object. In this example, export the filter as an object. Specify the variable name as Hd1.
Click Export.
Filter the input signal in the command window with the exported filter object. Plot the result for
the first ten periods of the 100-Hz sinusoid.
y2 = filter(Hd1,x);
plot(t(1:100),x(1:100),'k');
hold on;
plot(t(1:100),y1(1:100),'r','linewidth',2);
legend('Original Signal','Filtered Data','Location','SouthEast');
xlabel('Seconds'); ylabel('Amplitude');
Select File —> Generate MATLAB Code to generate a MATLAB function to create a filter
object using your specifications.
You can also use the interactive tool filterbuilder to design your filter.
Bandpass Filters — Minimum-Order FIR and IIR Systems
This example shows you how to design a bandpass filter and filter data with minimum-order FIR
equiripple and IIR Butterworth filters. The example uses fdesign.bandpass and the interactive
tool fdatool.
You can model many real-world signals as a superposition of oscillating components, a low-
frequency trend, and additive noise. For example, economic data often contain oscillations,
which represent cycles superimposed on a slowly varying upward or downward trend. In
addition, there is an additive noise component, which is a combination of measurement error
and the inherent random fluctuations in the process.
In these examples, assume you sample some process every day for 1 year. Assume the
process has oscillations on approximately one-week and one-month scales. In addition, there is
a low-frequency upward trend in the data and additive N(0,1/4) white Gaussian noise.
Create the signal as a superposition of two sine waves with frequencies of 1/7 and 1/30
cycles/day. Add a low-frequency increasing trend term and N(0,1/4) white Gaussian noise. Set
the random number generator to the default state for reproducible results. The data is sampled
at 1 sample/day. Plot the resulting signal and the power spectral density (PSD) estimate.
rng default;
Fs =1;
n = 1:365;
x = cos(2*pi*(1/7)*n)+cos(2*pi*(1/30)*n-pi/4);
trend = 3*sin(2*pi*(1/1480)*n);
y = x+trend+0.5*randn(size(n));
subplot(211);
plot(n,y); xlabel('Days'); set(gca,'xlim',[1 365]);
grid on;
subplot(212);
[pxx,f] = periodogram(y,[],length(y),Fs);
plot(f,10*log10(pxx));
xlabel('Cycles/day'); ylabel('dB'); grid on;
The low-frequency trend appears in the power spectral density estimate as increased low-
frequency power. The low-frequency power appears approximately 10 dB above the oscillation
at 1/30 cycles/day. Use this information in the specifications for the filter stopbands.
Design minimum-order FIR equiripple and IIR Butterworth filters with the following
specifications: passband from [1/40,1/4] cycles/day and stopbands from [0,1/60] and [1/4,1/2]
cycles/day. Set both stopband attenuations to 10 dB and the passband ripple tolerance to 1 dB.
d = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',...
1/60,1/40,1/4,1/2,10,1,10,1);
Hd1 = design(d,'equiripple');
Hd2 = design(d,'butter');
Compare the order of the FIR and IIR filters and the unwrapped phase responses.
fprintf('The order of the FIR filter is %dn',length(Hd1.Numerator)-1);
[b,a] = sos2tf(Hd2.sosMatrix,Hd2.ScaleValues);
fprintf('The order of the IIR filter is %dn',length(max(b,a))-1);
[phifir,w] = phasez(Hd1,[],1);
[phiiir,w] = phasez(Hd2,[],1);
plot(w,unwrap(phifir),'b'); hold on;
plot(w,unwrap(phiiir),'r'); grid on;
xlabel('Cycles/Day'); ylabel('Radians');
legend('FIR Equiripple Filter','IIR Butterworth Filter');
The IIR filter has a much lower order that the FIR filter. However, the FIR filter has a linear
phase response over the passband, while the IIR filter does not. The FIR filter delays all
frequencies in the filter passband equally, while the IIR filter does not.
Additionally, the rate of change of the phase per unit of frequency is greater in the FIR filter than
in the IIR filter.
Design a lowpass FIR equiripple filter for comparison. The lowpass filter specifications are:
passband [0,1/4] cycles/day, stopband attenuation equal to 10 dB, and the passband ripple
tolerance set to 1 dB.
dlow = fdesign.lowpass('Fp,Fst,Ap,Ast',1/4,1/2,1,10,1);
Hdlow = design(dlow,'equiripple');
Filter the data with the bandpass and lowpass filters.
yfir = filter(Hd1,y);
yiir = filter(Hd2,y);
ylow = filter(Hdlow,y);
Plot the PSD estimate of the bandpass IIR filter output. You can replace yiir with yfir in the
following code to view the PSD estimate of the FIR bandpass filter output.
[pxx,f] = periodogram(yiir,[],length(yiir),Fs);
plot(f,10*log10(pxx));
xlabel('Cycles/day'); ylabel('dB'); grid on;
The PSD estimate shows the bandpass filter attenuates the low-frequency trend and high-
frequency noise.
Plot the first 120 days of FIR and IIR filter output.
plot(n(1:120),yfir(1:120),'b');
hold on;
plot(n(1:120),yiir(1:120),'r');
xlabel('Days'); axis([1 120 -2.8 2.8]);
legend('FIR bandpass filter output','IIR bandpass filter output',...
'Location','SouthEast');
The increased phase delay in the FIR filter is evident in the filter output.
Plot the lowpass FIR filter output superimposed on the superposition of the 7-day and 30-day
cycles for comparison.
plot(n,x,'k');
hold on;
plot(n,ylow,'r'); set(gca,'xlim',[1 365]);
legend('7-day and 30-day cycles','FIR lowpass filter output',...
'Location','NorthWest');
xlabel('Days');
You can see in the preceding plot that the low-frequency trend is evident in the lowpass filter
output. While the lowpass filter preserves the 7-day and 30-day cycles, the bandpass filters
perform better in this example because the bandpass filters also remove the low-frequency
trend.
Design and implement the bandpass Butterworth (IIR) filter with the interactive tool fdatool.
Start FDATool by entering
fdatool
at the command line.
Set the Response Type to Bandpass. Set the Design Method to IIR and select
the Butterworth design.
Under Filter Order, select Minimum order.
Under Frequency Specifications. Set Units to Hz, Fs: to 1 , Fstop1: to 1/60, Fpass1: to
1/40, Fpass2: to 1/4, and Fstop2: to 1/2. UnderMagnitude Specifications,
set Astop1: and Astop2: to 10 and Apass: to 1.
Click Design Filter.
Select File —> Export... to export your IIR filter to the MATLAB workspace as coefficients or a
filter object. In this example, export the filter as an object. Specify the variable name as Hd3.
Click Export.
Filter the input signal in the command window with the exported filter object.
yfilt = filter(Hd3,x);
Select File —> Generate MATLAB Code to generate a MATLAB function to create a filter
object using your specifications.
You can also use the interactive tool filterbuilder to design your filter.
Zero-Phase Filtering
These examples show you how to perform zero-phase filtering. The signal and filters are
described in Lowpass FIR Filter — Window Method and Bandpass Filters — Minimum-Order
FIR and IIR Systems.
Repeat the signal generation and lowpass filter design with fir1 and fdesign.lowpass. You do not
have to execute the following code if you already have these variables in your workspace.
rng default;
Fs = 1000;
t = linspace(0,1,Fs);
x = cos(2*pi*100*t)+0.5*randn(size(t));
% Using fir1
fc = 150;
Wn = (2/Fs)*fc;
b = fir1(20,Wn,'low',kaiser(21,3));
% Using fdesign.lowpass
d = fdesign.lowpass('N,Fc',20,150,Fs);
Hd = design(d,'window','Window',kaiser(21,3));
Filter the data using filter. Plot the first 100 points of the filter output along with a superimposed
sinusoid with the same amplitude and initial phase as the input signal.
yout = filter(Hd,x);
xin = cos(2*pi*100*t);
plot(t(1:100),xin(1:100),'k');
hold on; grid on;
plot(t(1:100),yout(1:100),'r','linewidth',2);
xlabel('Seconds'); ylabel('Amplitude');
legend('Input Sine Wave','Filtered Data',...
'Location','NorthEast');
Looking at the initial 0.01 seconds of the filtered data, you see that the output is delayed with
respect to the input. The delay appears to be approximately 0.01 seconds, which is almost 1/2
the length of the FIR filter in samples (10*0.001).
This delay is due to the filter's phase response. The FIR filter in these examples is a type I
linear-phase filter. The group delay of the filter is 10 samples.
Plot the group delay using fvtool.
fvtool(Hd,'analysis','grpdelay');
In many applications, phase distortion is acceptable. This is particularly true when phase
response is linear. In other applications, it is desirable to have a filter with a zero-phase
response. A zero-phase response is not technically possibly in a noncausal filter. However, you
can implement zero-phase filtering using a causal filter with filtfilt.
Filter the input signal using filtfilt. Plot the responses to compare the filter outputs obtained
with filter and filtfilt.
yzp = filtfilt(Hd.Numerator,1,x);
% or yzp = filtfilt(b,1,x);
plot(t(1:100),xin(1:100),'k');
hold on;
plot(t(1:100),yout(1:100),'r','linewidth',2);
plot(t(1:100),yzp(1:100),'b','linewidth',2);
xlabel('Seconds'); ylabel('Amplitude');
legend('100-Hz Sine Wave','Filtered Signal','Zero-phase Filtering',...
'Location','NorthEast');
In the preceding figure, you can see that the output of filtfilt does not exhibit the delay due to the
phase response of the FIR filter.
The IIR bandpass filter designed in Bandpass Filters — Minimum-Order FIR and IIR Systems is
a biquad filter. Stated equivalently, the IIR filter is in the form of cascaded second-order
sections. To implement zero-phase filtering with a discrete-time biquad filter, you must input the
matrix of second-order sections and the gain values for each of those sections into filtfilt.
Zero phase filter the data in Bandpass Filters — Minimum-Order FIR and IIR Systems with the
IIR bandpass filter. For convenience, the code to generate the signal and filter is repeated. You
do not have to execute this code if you already have these variables in your workspace.
Generate the data.
rng default;
Fs =1;
n = 1:365;
x = cos(2*pi*(1/7)*n)+cos(2*pi*(1/30)*n-pi/4);
trend = 3*sin(2*pi*(1/1480)*n);
y = x+trend+0.5*randn(size(n));
Specify and design the filter.
d = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',...
1/60,1/40,1/4,1/2,10,1,10,1);
Hd2 = design(d,'butter');
Use filtfilt to zero-phase filter the input. Input the matrix of second-order sections and the gain
(scale) value of 1 along with your signal.
yzpiir = filtfilt(Hd2.sosMatrix,Hd2.ScaleValues,y);
visit us at www.assignmentpedia.com or email us at info@assignmentpedia.com or call us at +1 520 8371215

More Related Content

What's hot

Filters two design_with_matlab
Filters two design_with_matlabFilters two design_with_matlab
Filters two design_with_matlabresearchwork
 
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignDSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignAmr E. Mohamed
 
Design and realization of fir filter using chebyshev window
Design and realization of fir filter using chebyshev windowDesign and realization of fir filter using chebyshev window
Design and realization of fir filter using chebyshev windowSubhadeep Chakraborty
 
design of sampling filter
design of sampling filter design of sampling filter
design of sampling filter Anuj Arora
 
Optimum FIR Filtersfor Digital Pulse Compression of Biphase Barker Codes with...
Optimum FIR Filtersfor Digital Pulse Compression of Biphase Barker Codes with...Optimum FIR Filtersfor Digital Pulse Compression of Biphase Barker Codes with...
Optimum FIR Filtersfor Digital Pulse Compression of Biphase Barker Codes with...IJERA Editor
 
DSP_FOEHU - Lec 10 - FIR Filter Design
DSP_FOEHU - Lec 10 - FIR Filter DesignDSP_FOEHU - Lec 10 - FIR Filter Design
DSP_FOEHU - Lec 10 - FIR Filter DesignAmr E. Mohamed
 
Analysis of Butterworth and Chebyshev Filters for ECG Denoising Using Wavelets
Analysis of Butterworth and Chebyshev Filters for ECG Denoising Using WaveletsAnalysis of Butterworth and Chebyshev Filters for ECG Denoising Using Wavelets
Analysis of Butterworth and Chebyshev Filters for ECG Denoising Using WaveletsIOSR Journals
 
Design And Performance of Finite impulse Response Filter Using Hyperbolic Cos...
Design And Performance of Finite impulse Response Filter Using Hyperbolic Cos...Design And Performance of Finite impulse Response Filter Using Hyperbolic Cos...
Design And Performance of Finite impulse Response Filter Using Hyperbolic Cos...IDES Editor
 
Synchronous Time and Frequency Domain Analysis of Embedded Systems
Synchronous Time and Frequency Domain Analysis of Embedded SystemsSynchronous Time and Frequency Domain Analysis of Embedded Systems
Synchronous Time and Frequency Domain Analysis of Embedded SystemsRohde & Schwarz North America
 
Dss
Dss Dss
Dss nil65
 
Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingDsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingAmr E. Mohamed
 
Fast Fourier Transform
Fast Fourier TransformFast Fourier Transform
Fast Fourier Transformop205
 
Synchronous Time / Frequency Domain Measurements Using a Digital Oscilloscope...
Synchronous Time / Frequency Domain Measurements Using a Digital Oscilloscope...Synchronous Time / Frequency Domain Measurements Using a Digital Oscilloscope...
Synchronous Time / Frequency Domain Measurements Using a Digital Oscilloscope...Rohde & Schwarz North America
 

What's hot (17)

Lecture13
Lecture13Lecture13
Lecture13
 
Dsp lecture vol 6 design of fir
Dsp lecture vol 6 design of firDsp lecture vol 6 design of fir
Dsp lecture vol 6 design of fir
 
Filters two design_with_matlab
Filters two design_with_matlabFilters two design_with_matlab
Filters two design_with_matlab
 
Design of Filters PPT
Design of Filters PPTDesign of Filters PPT
Design of Filters PPT
 
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignDSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
 
Design and realization of fir filter using chebyshev window
Design and realization of fir filter using chebyshev windowDesign and realization of fir filter using chebyshev window
Design and realization of fir filter using chebyshev window
 
design of sampling filter
design of sampling filter design of sampling filter
design of sampling filter
 
Optimum FIR Filtersfor Digital Pulse Compression of Biphase Barker Codes with...
Optimum FIR Filtersfor Digital Pulse Compression of Biphase Barker Codes with...Optimum FIR Filtersfor Digital Pulse Compression of Biphase Barker Codes with...
Optimum FIR Filtersfor Digital Pulse Compression of Biphase Barker Codes with...
 
DSP_FOEHU - Lec 10 - FIR Filter Design
DSP_FOEHU - Lec 10 - FIR Filter DesignDSP_FOEHU - Lec 10 - FIR Filter Design
DSP_FOEHU - Lec 10 - FIR Filter Design
 
Analysis of Butterworth and Chebyshev Filters for ECG Denoising Using Wavelets
Analysis of Butterworth and Chebyshev Filters for ECG Denoising Using WaveletsAnalysis of Butterworth and Chebyshev Filters for ECG Denoising Using Wavelets
Analysis of Butterworth and Chebyshev Filters for ECG Denoising Using Wavelets
 
Digital Filters Part 2
Digital Filters Part 2Digital Filters Part 2
Digital Filters Part 2
 
Design And Performance of Finite impulse Response Filter Using Hyperbolic Cos...
Design And Performance of Finite impulse Response Filter Using Hyperbolic Cos...Design And Performance of Finite impulse Response Filter Using Hyperbolic Cos...
Design And Performance of Finite impulse Response Filter Using Hyperbolic Cos...
 
Synchronous Time and Frequency Domain Analysis of Embedded Systems
Synchronous Time and Frequency Domain Analysis of Embedded SystemsSynchronous Time and Frequency Domain Analysis of Embedded Systems
Synchronous Time and Frequency Domain Analysis of Embedded Systems
 
Dss
Dss Dss
Dss
 
Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingDsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
 
Fast Fourier Transform
Fast Fourier TransformFast Fourier Transform
Fast Fourier Transform
 
Synchronous Time / Frequency Domain Measurements Using a Digital Oscilloscope...
Synchronous Time / Frequency Domain Measurements Using a Digital Oscilloscope...Synchronous Time / Frequency Domain Measurements Using a Digital Oscilloscope...
Synchronous Time / Frequency Domain Measurements Using a Digital Oscilloscope...
 

Similar to Filter Implementation And Evaluation Project

Audio Signal Processing
Audio Signal Processing Audio Signal Processing
Audio Signal Processing Ahmed A. Arefin
 
Design of digital filters
Design of digital filtersDesign of digital filters
Design of digital filtersNaila Bibi
 
DSP_FOEHU - Lec 07 - Digital Filters
DSP_FOEHU - Lec 07 - Digital FiltersDSP_FOEHU - Lec 07 - Digital Filters
DSP_FOEHU - Lec 07 - Digital FiltersAmr E. Mohamed
 
Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağıMerve Cvdr
 
Fourier project presentation
Fourier project  presentationFourier project  presentation
Fourier project presentation志璿 楊
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio filesMinh Anh Nguyen
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio filesMinh Anh Nguyen
 
Speech Processing in Stressing Co-Channel Interference Using the Wigner Distr...
Speech Processing in Stressing Co-Channel Interference Using the Wigner Distr...Speech Processing in Stressing Co-Channel Interference Using the Wigner Distr...
Speech Processing in Stressing Co-Channel Interference Using the Wigner Distr...CSCJournals
 
Efficient Spectral Analysis Through Effective Reduction of Adjacent Channel I...
Efficient Spectral Analysis Through Effective Reduction of Adjacent Channel I...Efficient Spectral Analysis Through Effective Reduction of Adjacent Channel I...
Efficient Spectral Analysis Through Effective Reduction of Adjacent Channel I...CSCJournals
 
Analysis of different FIR Filter Design Method in terms of Resource Utilizati...
Analysis of different FIR Filter Design Method in terms of Resource Utilizati...Analysis of different FIR Filter Design Method in terms of Resource Utilizati...
Analysis of different FIR Filter Design Method in terms of Resource Utilizati...ijsrd.com
 
DESIGN OF QUATERNARY LOGICAL CIRCUIT USING VOLTAGE AND CURRENT MODE LOGIC
DESIGN OF QUATERNARY LOGICAL CIRCUIT USING VOLTAGE AND CURRENT MODE LOGICDESIGN OF QUATERNARY LOGICAL CIRCUIT USING VOLTAGE AND CURRENT MODE LOGIC
DESIGN OF QUATERNARY LOGICAL CIRCUIT USING VOLTAGE AND CURRENT MODE LOGICVLSICS Design
 
Design Technique of Bandpass FIR filter using Various Window Function
Design Technique of Bandpass FIR filter using Various Window FunctionDesign Technique of Bandpass FIR filter using Various Window Function
Design Technique of Bandpass FIR filter using Various Window FunctionIOSR Journals
 
Design Technique of Bandpass FIR filter using Various Window Function
Design Technique of Bandpass FIR filter using Various Window FunctionDesign Technique of Bandpass FIR filter using Various Window Function
Design Technique of Bandpass FIR filter using Various Window FunctionIOSR Journals
 
Vidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systemsVidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systemsanilkurhekar
 
INDUSTRIAL TRAINING REPORT
INDUSTRIAL TRAINING REPORTINDUSTRIAL TRAINING REPORT
INDUSTRIAL TRAINING REPORTABHISHEK DABRAL
 
SignalDecompositionTheory.pptx
SignalDecompositionTheory.pptxSignalDecompositionTheory.pptx
SignalDecompositionTheory.pptxPriyankaDarshana
 

Similar to Filter Implementation And Evaluation Project (20)

Audio Signal Processing
Audio Signal Processing Audio Signal Processing
Audio Signal Processing
 
Design of digital filters
Design of digital filtersDesign of digital filters
Design of digital filters
 
DSP_FOEHU - Lec 07 - Digital Filters
DSP_FOEHU - Lec 07 - Digital FiltersDSP_FOEHU - Lec 07 - Digital Filters
DSP_FOEHU - Lec 07 - Digital Filters
 
Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağı
 
Fourier project presentation
Fourier project  presentationFourier project  presentation
Fourier project presentation
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
 
Speech Processing in Stressing Co-Channel Interference Using the Wigner Distr...
Speech Processing in Stressing Co-Channel Interference Using the Wigner Distr...Speech Processing in Stressing Co-Channel Interference Using the Wigner Distr...
Speech Processing in Stressing Co-Channel Interference Using the Wigner Distr...
 
Efficient Spectral Analysis Through Effective Reduction of Adjacent Channel I...
Efficient Spectral Analysis Through Effective Reduction of Adjacent Channel I...Efficient Spectral Analysis Through Effective Reduction of Adjacent Channel I...
Efficient Spectral Analysis Through Effective Reduction of Adjacent Channel I...
 
Analysis of different FIR Filter Design Method in terms of Resource Utilizati...
Analysis of different FIR Filter Design Method in terms of Resource Utilizati...Analysis of different FIR Filter Design Method in terms of Resource Utilizati...
Analysis of different FIR Filter Design Method in terms of Resource Utilizati...
 
DESIGN OF QUATERNARY LOGICAL CIRCUIT USING VOLTAGE AND CURRENT MODE LOGIC
DESIGN OF QUATERNARY LOGICAL CIRCUIT USING VOLTAGE AND CURRENT MODE LOGICDESIGN OF QUATERNARY LOGICAL CIRCUIT USING VOLTAGE AND CURRENT MODE LOGIC
DESIGN OF QUATERNARY LOGICAL CIRCUIT USING VOLTAGE AND CURRENT MODE LOGIC
 
Dsp manual
Dsp manualDsp manual
Dsp manual
 
Design Technique of Bandpass FIR filter using Various Window Function
Design Technique of Bandpass FIR filter using Various Window FunctionDesign Technique of Bandpass FIR filter using Various Window Function
Design Technique of Bandpass FIR filter using Various Window Function
 
Design Technique of Bandpass FIR filter using Various Window Function
Design Technique of Bandpass FIR filter using Various Window FunctionDesign Technique of Bandpass FIR filter using Various Window Function
Design Technique of Bandpass FIR filter using Various Window Function
 
Vidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systemsVidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systems
 
Exp passive filter (5)
Exp passive filter (5)Exp passive filter (5)
Exp passive filter (5)
 
N010237982
N010237982N010237982
N010237982
 
INDUSTRIAL TRAINING REPORT
INDUSTRIAL TRAINING REPORTINDUSTRIAL TRAINING REPORT
INDUSTRIAL TRAINING REPORT
 
Exp passive filter (4)
Exp passive filter (4)Exp passive filter (4)
Exp passive filter (4)
 
SignalDecompositionTheory.pptx
SignalDecompositionTheory.pptxSignalDecompositionTheory.pptx
SignalDecompositionTheory.pptx
 

More from Assignmentpedia

Transmitter side components
Transmitter side componentsTransmitter side components
Transmitter side componentsAssignmentpedia
 
Single object range detection
Single object range detectionSingle object range detection
Single object range detectionAssignmentpedia
 
Sequential radar tracking
Sequential radar trackingSequential radar tracking
Sequential radar trackingAssignmentpedia
 
Radar cross section project
Radar cross section projectRadar cross section project
Radar cross section projectAssignmentpedia
 
Radar application project help
Radar application project helpRadar application project help
Radar application project helpAssignmentpedia
 
Parallel computing homework help
Parallel computing homework helpParallel computing homework help
Parallel computing homework helpAssignmentpedia
 
Network costing analysis
Network costing analysisNetwork costing analysis
Network costing analysisAssignmentpedia
 
Matlab simulation project
Matlab simulation projectMatlab simulation project
Matlab simulation projectAssignmentpedia
 
Matlab programming project
Matlab programming projectMatlab programming project
Matlab programming projectAssignmentpedia
 
Image processing project using matlab
Image processing project using matlabImage processing project using matlab
Image processing project using matlabAssignmentpedia
 
Help with root locus homework1
Help with root locus homework1Help with root locus homework1
Help with root locus homework1Assignmentpedia
 
Computer Networks Homework Help
Computer Networks Homework HelpComputer Networks Homework Help
Computer Networks Homework HelpAssignmentpedia
 
Theory of computation homework help
Theory of computation homework helpTheory of computation homework help
Theory of computation homework helpAssignmentpedia
 
Econometrics Homework Help
Econometrics Homework HelpEconometrics Homework Help
Econometrics Homework HelpAssignmentpedia
 

More from Assignmentpedia (20)

Transmitter side components
Transmitter side componentsTransmitter side components
Transmitter side components
 
Single object range detection
Single object range detectionSingle object range detection
Single object range detection
 
Sequential radar tracking
Sequential radar trackingSequential radar tracking
Sequential radar tracking
 
Resolution project
Resolution projectResolution project
Resolution project
 
Radar cross section project
Radar cross section projectRadar cross section project
Radar cross section project
 
Radar application project help
Radar application project helpRadar application project help
Radar application project help
 
Parallel computing homework help
Parallel computing homework helpParallel computing homework help
Parallel computing homework help
 
Network costing analysis
Network costing analysisNetwork costing analysis
Network costing analysis
 
Matlab simulation project
Matlab simulation projectMatlab simulation project
Matlab simulation project
 
Matlab programming project
Matlab programming projectMatlab programming project
Matlab programming project
 
Links design
Links designLinks design
Links design
 
Image processing project using matlab
Image processing project using matlabImage processing project using matlab
Image processing project using matlab
 
Help with root locus homework1
Help with root locus homework1Help with root locus homework1
Help with root locus homework1
 
Transmitter subsystem
Transmitter subsystemTransmitter subsystem
Transmitter subsystem
 
Computer Networks Homework Help
Computer Networks Homework HelpComputer Networks Homework Help
Computer Networks Homework Help
 
Theory of computation homework help
Theory of computation homework helpTheory of computation homework help
Theory of computation homework help
 
Econometrics Homework Help
Econometrics Homework HelpEconometrics Homework Help
Econometrics Homework Help
 
Video Codec
Video CodecVideo Codec
Video Codec
 
Radar Spectral Analysis
Radar Spectral AnalysisRadar Spectral Analysis
Radar Spectral Analysis
 
Pi Controller
Pi ControllerPi Controller
Pi Controller
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Filter Implementation And Evaluation Project

  • 1. FILTER IMPLEMENTATION AND EVALUATION USING MATLAB Our online Tutors are available 24*7 to provide Help with Filter Implementation and Evaluation Homework/Assignment or a long term Graduate/Undergraduate Filter Implementation and Evaluation Project. Our Tutors being experienced and proficient in Filter Implementation and Evaluation ensure to provide high quality Filter Implementation and Evaluation Homework Help. Upload your Filter Implementation and Evaluation Assignment at ‘Submit Your Assignment’ button or email it to info@assignmentpedia.com. You can use our ‘Live Chat’ option to schedule an Online Tutoring session with our Filter Implementation and Evaluation Tutors. LOWPASS FIR FILTER This example show how to design and implement an FIR filter using the command line functions: fir1 and fdesign.lowpass, and the interactive tool fdatool. To filter the input signal, these examples use the filter command. The examples in Zero-Phase Filtering show you how to implement zero-phase filtering with filtfilt. Create a signal to use in the examples. The signal is a 100-Hz sinewave in additive N(0,1/4) white Gaussian noise. Set the random number generator to the default state for reproducible results. rng default; Fs = 1000; t = linspace(0,1,Fs); x = cos (2*pi*100*t)+0.5*randn(size(t)); The filter design is an FIR lowpass filter with order equal to 20 and a cutoff frequency of 150 Hz. Use a Kasier window with length one sample greater than the filter order and β=3. See kaiser for details on the Kaiser window. Use fir1 to design the filter. fir1 requires normalized frequencies in the interval [0,1], where 1 is (1)π radians/sample. To use fir1, you must convert all frequency specifications to normalized frequencies. Design the filter and view the filter's magnitude response. fc = 150; Wn = (2/Fs)*fc; b = fir1(20,Wn,'low',kaiser(21,3)); fvtool(b,1,'Fs',Fs); Apply the filter to the signal and plot the result for the first ten periods of the 100-Hz sinusoid. y = filter(b,1,x); plot(t(1:100),x(1:100),'k'); hold on; plot(t(1:100),y(1:100),'r','linewidth',2); legend('Original Signal','Filtered Data','Location','SouthEast'); xlabel('Seconds'); ylabel('Amplitude');
  • 2. Design the same filter using fdesign.lowpass. Set the filter specifications using the 'N,Fc' specification string. With fdesign.lowpass, you can specify your filter design in Hz. Fs = 1000; d = fdesign.lowpass('N,Fc',20,150,Fs); Hd = design(d,'window','Window',kaiser(21,3)); Filter the data and plot the result. y1 = filter(Hd,x); plot(t(1:100),x(1:100),'k'); hold on; plot(t(1:100),y1(1:100),'r','linewidth',2); legend('Original Signal','Filtered Data','Location','SouthEast'); xlabel('Seconds'); ylabel('Amplitude'); Design and implement a lowpass FIR filter using the window method with the interactive tool fdatool. Start FDATool by entering
  • 3. fdatool at the command line. Set the Response Type to Lowpass. Set the Design Method to FIR and select the Window method. Under Filter Order, select Specify order. Set the order to 20. Under Frequency Specifications. Set Units to Hz, Fs: to 1000, and Fc: to 150. Click Design Filter. Select File —>Export... to export your FIR filter to the MATLAB® workspace as coefficients or a filter object. In this example, export the filter as an object. Specify the variable name as Hd1.
  • 4. Click Export. Filter the input signal in the command window with the exported filter object. Plot the result for the first ten periods of the 100-Hz sinusoid. y2 = filter(Hd1,x); plot(t(1:100),x(1:100),'k'); hold on; plot(t(1:100),y1(1:100),'r','linewidth',2); legend('Original Signal','Filtered Data','Location','SouthEast'); xlabel('Seconds'); ylabel('Amplitude'); Select File —> Generate MATLAB Code to generate a MATLAB function to create a filter object using your specifications. You can also use the interactive tool filterbuilder to design your filter. Bandpass Filters — Minimum-Order FIR and IIR Systems This example shows you how to design a bandpass filter and filter data with minimum-order FIR equiripple and IIR Butterworth filters. The example uses fdesign.bandpass and the interactive tool fdatool. You can model many real-world signals as a superposition of oscillating components, a low- frequency trend, and additive noise. For example, economic data often contain oscillations, which represent cycles superimposed on a slowly varying upward or downward trend. In addition, there is an additive noise component, which is a combination of measurement error and the inherent random fluctuations in the process. In these examples, assume you sample some process every day for 1 year. Assume the process has oscillations on approximately one-week and one-month scales. In addition, there is a low-frequency upward trend in the data and additive N(0,1/4) white Gaussian noise. Create the signal as a superposition of two sine waves with frequencies of 1/7 and 1/30 cycles/day. Add a low-frequency increasing trend term and N(0,1/4) white Gaussian noise. Set the random number generator to the default state for reproducible results. The data is sampled at 1 sample/day. Plot the resulting signal and the power spectral density (PSD) estimate. rng default; Fs =1; n = 1:365; x = cos(2*pi*(1/7)*n)+cos(2*pi*(1/30)*n-pi/4); trend = 3*sin(2*pi*(1/1480)*n); y = x+trend+0.5*randn(size(n));
  • 5. subplot(211); plot(n,y); xlabel('Days'); set(gca,'xlim',[1 365]); grid on; subplot(212); [pxx,f] = periodogram(y,[],length(y),Fs); plot(f,10*log10(pxx)); xlabel('Cycles/day'); ylabel('dB'); grid on; The low-frequency trend appears in the power spectral density estimate as increased low- frequency power. The low-frequency power appears approximately 10 dB above the oscillation at 1/30 cycles/day. Use this information in the specifications for the filter stopbands. Design minimum-order FIR equiripple and IIR Butterworth filters with the following specifications: passband from [1/40,1/4] cycles/day and stopbands from [0,1/60] and [1/4,1/2] cycles/day. Set both stopband attenuations to 10 dB and the passband ripple tolerance to 1 dB. d = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',... 1/60,1/40,1/4,1/2,10,1,10,1); Hd1 = design(d,'equiripple'); Hd2 = design(d,'butter');
  • 6. Compare the order of the FIR and IIR filters and the unwrapped phase responses. fprintf('The order of the FIR filter is %dn',length(Hd1.Numerator)-1); [b,a] = sos2tf(Hd2.sosMatrix,Hd2.ScaleValues); fprintf('The order of the IIR filter is %dn',length(max(b,a))-1); [phifir,w] = phasez(Hd1,[],1); [phiiir,w] = phasez(Hd2,[],1); plot(w,unwrap(phifir),'b'); hold on; plot(w,unwrap(phiiir),'r'); grid on; xlabel('Cycles/Day'); ylabel('Radians'); legend('FIR Equiripple Filter','IIR Butterworth Filter'); The IIR filter has a much lower order that the FIR filter. However, the FIR filter has a linear phase response over the passband, while the IIR filter does not. The FIR filter delays all frequencies in the filter passband equally, while the IIR filter does not. Additionally, the rate of change of the phase per unit of frequency is greater in the FIR filter than in the IIR filter.
  • 7. Design a lowpass FIR equiripple filter for comparison. The lowpass filter specifications are: passband [0,1/4] cycles/day, stopband attenuation equal to 10 dB, and the passband ripple tolerance set to 1 dB. dlow = fdesign.lowpass('Fp,Fst,Ap,Ast',1/4,1/2,1,10,1); Hdlow = design(dlow,'equiripple'); Filter the data with the bandpass and lowpass filters. yfir = filter(Hd1,y); yiir = filter(Hd2,y); ylow = filter(Hdlow,y); Plot the PSD estimate of the bandpass IIR filter output. You can replace yiir with yfir in the following code to view the PSD estimate of the FIR bandpass filter output. [pxx,f] = periodogram(yiir,[],length(yiir),Fs); plot(f,10*log10(pxx)); xlabel('Cycles/day'); ylabel('dB'); grid on;
  • 8. The PSD estimate shows the bandpass filter attenuates the low-frequency trend and high- frequency noise. Plot the first 120 days of FIR and IIR filter output. plot(n(1:120),yfir(1:120),'b'); hold on; plot(n(1:120),yiir(1:120),'r'); xlabel('Days'); axis([1 120 -2.8 2.8]); legend('FIR bandpass filter output','IIR bandpass filter output',... 'Location','SouthEast'); The increased phase delay in the FIR filter is evident in the filter output. Plot the lowpass FIR filter output superimposed on the superposition of the 7-day and 30-day cycles for comparison. plot(n,x,'k'); hold on; plot(n,ylow,'r'); set(gca,'xlim',[1 365]); legend('7-day and 30-day cycles','FIR lowpass filter output',...
  • 9. 'Location','NorthWest'); xlabel('Days'); You can see in the preceding plot that the low-frequency trend is evident in the lowpass filter output. While the lowpass filter preserves the 7-day and 30-day cycles, the bandpass filters perform better in this example because the bandpass filters also remove the low-frequency trend. Design and implement the bandpass Butterworth (IIR) filter with the interactive tool fdatool. Start FDATool by entering fdatool at the command line. Set the Response Type to Bandpass. Set the Design Method to IIR and select the Butterworth design. Under Filter Order, select Minimum order. Under Frequency Specifications. Set Units to Hz, Fs: to 1 , Fstop1: to 1/60, Fpass1: to 1/40, Fpass2: to 1/4, and Fstop2: to 1/2. UnderMagnitude Specifications, set Astop1: and Astop2: to 10 and Apass: to 1.
  • 10. Click Design Filter. Select File —> Export... to export your IIR filter to the MATLAB workspace as coefficients or a filter object. In this example, export the filter as an object. Specify the variable name as Hd3. Click Export. Filter the input signal in the command window with the exported filter object.
  • 11. yfilt = filter(Hd3,x); Select File —> Generate MATLAB Code to generate a MATLAB function to create a filter object using your specifications. You can also use the interactive tool filterbuilder to design your filter. Zero-Phase Filtering These examples show you how to perform zero-phase filtering. The signal and filters are described in Lowpass FIR Filter — Window Method and Bandpass Filters — Minimum-Order FIR and IIR Systems. Repeat the signal generation and lowpass filter design with fir1 and fdesign.lowpass. You do not have to execute the following code if you already have these variables in your workspace. rng default; Fs = 1000; t = linspace(0,1,Fs); x = cos(2*pi*100*t)+0.5*randn(size(t)); % Using fir1 fc = 150; Wn = (2/Fs)*fc; b = fir1(20,Wn,'low',kaiser(21,3)); % Using fdesign.lowpass d = fdesign.lowpass('N,Fc',20,150,Fs); Hd = design(d,'window','Window',kaiser(21,3)); Filter the data using filter. Plot the first 100 points of the filter output along with a superimposed sinusoid with the same amplitude and initial phase as the input signal. yout = filter(Hd,x); xin = cos(2*pi*100*t); plot(t(1:100),xin(1:100),'k'); hold on; grid on; plot(t(1:100),yout(1:100),'r','linewidth',2); xlabel('Seconds'); ylabel('Amplitude'); legend('Input Sine Wave','Filtered Data',... 'Location','NorthEast');
  • 12. Looking at the initial 0.01 seconds of the filtered data, you see that the output is delayed with respect to the input. The delay appears to be approximately 0.01 seconds, which is almost 1/2 the length of the FIR filter in samples (10*0.001). This delay is due to the filter's phase response. The FIR filter in these examples is a type I linear-phase filter. The group delay of the filter is 10 samples. Plot the group delay using fvtool. fvtool(Hd,'analysis','grpdelay'); In many applications, phase distortion is acceptable. This is particularly true when phase response is linear. In other applications, it is desirable to have a filter with a zero-phase response. A zero-phase response is not technically possibly in a noncausal filter. However, you can implement zero-phase filtering using a causal filter with filtfilt. Filter the input signal using filtfilt. Plot the responses to compare the filter outputs obtained with filter and filtfilt. yzp = filtfilt(Hd.Numerator,1,x); % or yzp = filtfilt(b,1,x); plot(t(1:100),xin(1:100),'k');
  • 13. hold on; plot(t(1:100),yout(1:100),'r','linewidth',2); plot(t(1:100),yzp(1:100),'b','linewidth',2); xlabel('Seconds'); ylabel('Amplitude'); legend('100-Hz Sine Wave','Filtered Signal','Zero-phase Filtering',... 'Location','NorthEast'); In the preceding figure, you can see that the output of filtfilt does not exhibit the delay due to the phase response of the FIR filter. The IIR bandpass filter designed in Bandpass Filters — Minimum-Order FIR and IIR Systems is a biquad filter. Stated equivalently, the IIR filter is in the form of cascaded second-order sections. To implement zero-phase filtering with a discrete-time biquad filter, you must input the matrix of second-order sections and the gain values for each of those sections into filtfilt. Zero phase filter the data in Bandpass Filters — Minimum-Order FIR and IIR Systems with the IIR bandpass filter. For convenience, the code to generate the signal and filter is repeated. You do not have to execute this code if you already have these variables in your workspace. Generate the data. rng default;
  • 14. Fs =1; n = 1:365; x = cos(2*pi*(1/7)*n)+cos(2*pi*(1/30)*n-pi/4); trend = 3*sin(2*pi*(1/1480)*n); y = x+trend+0.5*randn(size(n)); Specify and design the filter. d = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',... 1/60,1/40,1/4,1/2,10,1,10,1); Hd2 = design(d,'butter'); Use filtfilt to zero-phase filter the input. Input the matrix of second-order sections and the gain (scale) value of 1 along with your signal. yzpiir = filtfilt(Hd2.sosMatrix,Hd2.ScaleValues,y); visit us at www.assignmentpedia.com or email us at info@assignmentpedia.com or call us at +1 520 8371215