SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
FILTER IMPLEMENTATION AND EVALUATION USING MATLAB (SAMPLE ASSIGNMENT)
For any Help with Filter Implementation And Evaluation Assignment upload
your Homework Assignment by clicking at “Submit Your Assignment”
button or you can email it to info@matlabassignmentexperts.com .To talk
to our Online Filter Implementation And Evaluation Project Tutors you can
call at +1 5208371215 or use our Live Chat option.
Lowpass FIR Filter
This sample assignment shows 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);

Contenu connexe

En vedette

Filter design techniques ch7 iir
Filter design techniques ch7 iirFilter design techniques ch7 iir
Filter design techniques ch7 iirFalah Mohammed
 
Interpixel redundancy
Interpixel redundancyInterpixel redundancy
Interpixel redundancyNaveen Kumar
 
design of sampling filter
design of sampling filter design of sampling filter
design of sampling filter Anuj Arora
 
Introductory Lecture to Audio Signal Processing
Introductory Lecture to Audio Signal ProcessingIntroductory Lecture to Audio Signal Processing
Introductory Lecture to Audio Signal ProcessingAngelo Salatino
 
Design of Filter Circuits using MATLAB, Multisim, and Excel
Design of Filter Circuits using MATLAB, Multisim, and ExcelDesign of Filter Circuits using MATLAB, Multisim, and Excel
Design of Filter Circuits using MATLAB, Multisim, and ExcelDavid Sandy
 
Image Compression Comparison Using Golden Section Transform, Haar Wavelet Tra...
Image Compression Comparison Using Golden Section Transform, Haar Wavelet Tra...Image Compression Comparison Using Golden Section Transform, Haar Wavelet Tra...
Image Compression Comparison Using Golden Section Transform, Haar Wavelet Tra...Jason Li
 
Dss
Dss Dss
Dss nil65
 
Gender detection using MATLAB
Gender detection using MATLABGender detection using MATLAB
Gender detection using MATLABTanmay Bakshi
 
Final project report
Final project reportFinal project report
Final project reportssuryawanshi
 
Seminar Report on image compression
Seminar Report on image compressionSeminar Report on image compression
Seminar Report on image compressionPradip Kumar
 
Fourier series example
Fourier series exampleFourier series example
Fourier series exampleAbi finni
 
image compression using matlab project report
image compression  using matlab project reportimage compression  using matlab project report
image compression using matlab project reportkgaurav113
 
Hardware Implementation Of QPSK Modulator for Satellite Communications
Hardware Implementation Of QPSK Modulator for Satellite CommunicationsHardware Implementation Of QPSK Modulator for Satellite Communications
Hardware Implementation Of QPSK Modulator for Satellite Communicationspradeepps88
 
Isi and nyquist criterion
Isi and nyquist criterionIsi and nyquist criterion
Isi and nyquist criterionsrkrishna341
 
Image processing and compression techniques
Image processing and compression techniquesImage processing and compression techniques
Image processing and compression techniquesAshwin Venkataraman
 

En vedette (19)

Filter design techniques ch7 iir
Filter design techniques ch7 iirFilter design techniques ch7 iir
Filter design techniques ch7 iir
 
Interpixel redundancy
Interpixel redundancyInterpixel redundancy
Interpixel redundancy
 
design of sampling filter
design of sampling filter design of sampling filter
design of sampling filter
 
Introductory Lecture to Audio Signal Processing
Introductory Lecture to Audio Signal ProcessingIntroductory Lecture to Audio Signal Processing
Introductory Lecture to Audio Signal Processing
 
Design of Filter Circuits using MATLAB, Multisim, and Excel
Design of Filter Circuits using MATLAB, Multisim, and ExcelDesign of Filter Circuits using MATLAB, Multisim, and Excel
Design of Filter Circuits using MATLAB, Multisim, and Excel
 
Image Compression Comparison Using Golden Section Transform, Haar Wavelet Tra...
Image Compression Comparison Using Golden Section Transform, Haar Wavelet Tra...Image Compression Comparison Using Golden Section Transform, Haar Wavelet Tra...
Image Compression Comparison Using Golden Section Transform, Haar Wavelet Tra...
 
Dss
Dss Dss
Dss
 
Gender detection using MATLAB
Gender detection using MATLABGender detection using MATLAB
Gender detection using MATLAB
 
Final project report
Final project reportFinal project report
Final project report
 
DSP MATLAB notes - Akshansh
DSP MATLAB notes - AkshanshDSP MATLAB notes - Akshansh
DSP MATLAB notes - Akshansh
 
Image compression
Image compression Image compression
Image compression
 
Seminar Report on image compression
Seminar Report on image compressionSeminar Report on image compression
Seminar Report on image compression
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
Jpeg compression
Jpeg compressionJpeg compression
Jpeg compression
 
image compression using matlab project report
image compression  using matlab project reportimage compression  using matlab project report
image compression using matlab project report
 
Design of Filters PPT
Design of Filters PPTDesign of Filters PPT
Design of Filters PPT
 
Hardware Implementation Of QPSK Modulator for Satellite Communications
Hardware Implementation Of QPSK Modulator for Satellite CommunicationsHardware Implementation Of QPSK Modulator for Satellite Communications
Hardware Implementation Of QPSK Modulator for Satellite Communications
 
Isi and nyquist criterion
Isi and nyquist criterionIsi and nyquist criterion
Isi and nyquist criterion
 
Image processing and compression techniques
Image processing and compression techniquesImage processing and compression techniques
Image processing and compression techniques
 

Plus de Matlab Assignment Experts

🚀 Need Expert MATLAB Assignment Help? Look No Further! 📊
🚀 Need Expert MATLAB Assignment Help? Look No Further! 📊🚀 Need Expert MATLAB Assignment Help? Look No Further! 📊
🚀 Need Expert MATLAB Assignment Help? Look No Further! 📊Matlab Assignment Experts
 

Plus de Matlab Assignment Experts (20)

🚀 Need Expert MATLAB Assignment Help? Look No Further! 📊
🚀 Need Expert MATLAB Assignment Help? Look No Further! 📊🚀 Need Expert MATLAB Assignment Help? Look No Further! 📊
🚀 Need Expert MATLAB Assignment Help? Look No Further! 📊
 
Matlab Assignment Help
Matlab Assignment HelpMatlab Assignment Help
Matlab Assignment Help
 
Matlab Assignment Help
Matlab Assignment HelpMatlab Assignment Help
Matlab Assignment Help
 
Matlab Assignment Help
Matlab Assignment HelpMatlab Assignment Help
Matlab Assignment Help
 
MAtlab Assignment Help
MAtlab Assignment HelpMAtlab Assignment Help
MAtlab Assignment Help
 
Matlab Assignment Help
Matlab Assignment HelpMatlab Assignment Help
Matlab Assignment Help
 
Matlab Assignment Help
Matlab Assignment HelpMatlab Assignment Help
Matlab Assignment Help
 
Matlab Homework Help
Matlab Homework HelpMatlab Homework Help
Matlab Homework Help
 
MATLAB Assignment Help
MATLAB Assignment HelpMATLAB Assignment Help
MATLAB Assignment Help
 
Matlab Homework Help
Matlab Homework HelpMatlab Homework Help
Matlab Homework Help
 
Matlab Assignment Help
Matlab Assignment HelpMatlab Assignment Help
Matlab Assignment Help
 
Computer vision (Matlab)
Computer vision (Matlab)Computer vision (Matlab)
Computer vision (Matlab)
 
Online Matlab Assignment Help
Online Matlab Assignment HelpOnline Matlab Assignment Help
Online Matlab Assignment Help
 
Modelling & Simulation Assignment Help
Modelling & Simulation Assignment HelpModelling & Simulation Assignment Help
Modelling & Simulation Assignment Help
 
Mechanical Assignment Help
Mechanical Assignment HelpMechanical Assignment Help
Mechanical Assignment Help
 
CURVE FITING ASSIGNMENT HELP
CURVE FITING ASSIGNMENT HELPCURVE FITING ASSIGNMENT HELP
CURVE FITING ASSIGNMENT HELP
 
Design and Manufacturing Homework Help
Design and Manufacturing Homework HelpDesign and Manufacturing Homework Help
Design and Manufacturing Homework Help
 
Digital Image Processing Assignment Help
Digital Image Processing Assignment HelpDigital Image Processing Assignment Help
Digital Image Processing Assignment Help
 
Signals and Systems Assignment Help
Signals and Systems Assignment HelpSignals and Systems Assignment Help
Signals and Systems Assignment Help
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 

Dernier

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
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
 
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
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 

Dernier (20)

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
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
 
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
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 

Filter Implementation And Evaluation Using MATLAB

  • 1. FILTER IMPLEMENTATION AND EVALUATION USING MATLAB (SAMPLE ASSIGNMENT) For any Help with Filter Implementation And Evaluation Assignment upload your Homework Assignment by clicking at “Submit Your Assignment” button or you can email it to info@matlabassignmentexperts.com .To talk to our Online Filter Implementation And Evaluation Project Tutors you can call at +1 5208371215 or use our Live Chat option. Lowpass FIR Filter This sample assignment shows 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 fdatool at the command line. Set the Response Type to Lowpass. Set the Design Method to FIR and select the Window method.
  • 3. 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.
  • 4. 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;
  • 5. 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);
  • 6. 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);
  • 7. 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');
  • 8. 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');
  • 9. 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'); hold on; plot(t(1:100),yout(1:100),'r','linewidth',2);
  • 13. 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;
  • 14. 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);