Using filterdesigner/FDAtool - setting parameters in the GUI and ge... (2024)

In the fdatool GUI, select the "Bandstop" radio-button option in the Response Type panel to create a Notch filter. In the Design Method panel, click the radio-button option next to "FIR" and select "Window" from the drop-down menu. This will give you the option to select Kaiser for the Window type in the Options panel.

In the Filter Order panel, you should specify a fixed order if you already know that you have a specific filter order you must use based on your application's constraints. Otherwise, select the "Minimum order" radio button option from the Filter Order panel.

Next, you need to input the frequency constraints to the Frequency Specifications panel. In both cases, Fs is the sample rate that is used to acquire the signal you are looking at. The other parameters will depend on what you selected for the Filter Order:

  • For a fixed filter order the filter will be designed such that the attenuation at Fc1 ("start" of notch) and Fc2 ("end" of notch) will be 6 dB (these are in the Frequency Specifications panel). If you make the notch very narrow while constraining the filter order, then this may only be realized with a very "strange" passband, so keep that in mind.
  • If you select "Minimum order" and give very "difficult" filter constraints, you may end up with an extremely long (and essentially impractical) filter, so keep that in mind as well. With "Minimum Order" selected, you have Fpass1, which specifies the frequency where the lower part of the "passband" ends (the start of the transition from "pass" to "stop" bands). Fstop1 is the end of this first transition. Fstop2 is the start of the transition from stop band back into pass band, and Fpass2 is where the second transition ends. In your 60 Hz example, This could be Fpass1 = 45, Fstop1 = 49, Fstop2 = 61, Fpass2 = 75, which puts 60 Hz in the middle of your stop band where the maximum attenuation would occur. Using these specifications for a signal sampled at 1 kHz and stopband attenuation (Astop) = 30 dB in the Magnitude Specifications panel, you get a filter order of 114, which is probably much higher than you would like for causal applications.

However, if that is suitable for your application, you could then make it easier to customize in the future by going to File in the GUI menu bar at the top, click Generate MATLAB Code, and click Filter Design Function. The generated function exported according to the example I gave above is shown here:

function Hd = notch_filter_60Hz

%NOTCH_FILTER_60HZ Returns a discrete-time filter object.

% MATLAB Code

% Generated by MATLAB(R) 9.2 and the DSP System Toolbox 9.4.

% Generated on: 30-Dec-2019 10:11:53

% FIR Window Bandstop filter designed using the FIR1 function.

% All frequency values are in Hz.

Fs = 1000; % Sampling Frequency

Fpass1 = 45; % First Passband Frequency

Fstop1 = 59; % First Stopband Frequency

Fstop2 = 61; % Second Stopband Frequency

Fpass2 = 75; % Second Passband Frequency

Dpass1 = 0.028774368332; % First Passband Ripple

Dstop = 0.031622776602; % Stopband Attenuation

Dpass2 = 0.057501127785; % Second Passband Ripple

flag = 'scale'; % Sampling Flag

% Calculate the order from the parameters using KAISERORD.

[N,Wn,BETA,TYPE] = kaiserord([Fpass1 Fstop1 Fstop2 Fpass2]/(Fs/2), [1 ...

0 1], [Dpass1 Dstop Dpass2]);

% Calculate the coefficients using the FIR1 function.

b = fir1(N, Wn, TYPE, kaiser(N+1, BETA), flag);

Hd = dfilt.dffir(b);

% [EOF]

Now, I can just call that function any time to get the filter object, Hd.

To address your need to enter in elements in a function as desired to generate an output filter, you could do something like:

function Hd = notch_filter_60Hz(varargin)

%NOTCH_FILTER_60HZ Returns a discrete-time filter object.

%

% Hd = notch_filter_60Hz; Return default Hd

% Hd = notch_filter_60Hz('paramname',value,...); (case-sensitive)

% --> e.g:

% >> Hd = notch_filter_60Hz('Fs',24414.0625,'Fpass1',40,...);

% MATLAB Code

% Generated by MATLAB(R) 9.2 and the DSP System Toolbox 9.4.

% Generated on: 30-Dec-2019 10:11:53

% FIR Window Bandstop filter designed using the FIR1 function.

% All frequency values are in Hz.

p = struct; % "Default values" struct

p.Fs = 1000; % Sampling Frequency

p.Fpass1 = 45; % First Passband Frequency

p.Fstop1 = 59; % First Stopband Frequency

p.Fstop2 = 61; % Second Stopband Frequency

p.Fpass2 = 75; % Second Passband Frequency

p.Dpass1 = 0.028774368332; % First Passband Ripple

p.Dstop = 0.031622776602; % Stopband Attenuation

p.Dpass2 = 0.057501127785; % Second Passband Ripple

p.flag = 'scale'; % Sampling Flag

% Parse any optional 'Name', value input pairs

for iV = 1:2:numel(varargin)

if isfield(p,varargin{iV})

p.(varargin{iV}) = varargin{iV+1};

end

end

% Calculate the order from the parameters using KAISERORD.

[N,Wn,BETA,TYPE] = kaiserord([p.Fpass1 p.Fstop1 p.Fstop2 p.Fpass2]/(p.Fs/2), [1 ...

0 1], [p.Dpass1 p.Dstop p.Dpass2]);

% Calculate the coefficients using the FIR1 function.

b = fir1(N, Wn, TYPE, kaiser(N+1, BETA), p.flag);

Hd = dfilt.dffir(b);

% [EOF]

This modified version allows you to enter input argument pairs that modify the "default" parameters you have generated using the fdatool originally. I think this is closer to what you want. Then from your custom GUI, you can enter whatever values you would like and get them to go into this generated function, which returns the filter object.

Note that to use the FIR filter you've generated, it again depends on your application. If you would like to see the phase offset induced by your filter, then use filter:

in = load('data.mat','x');

y = filter(Hd,in.x);

If you do not want to induce a phase offset, then use filtfilt:

in = load('data.mat','x');

b = Hd.Numerator;

a = 1;

y = filfilt(b,a,in.x); % just want to remove 60 Hz noise for example

As a final note, you may consider using an IIR filter because to achieve comparable attenuation you can do it with a lower order (since you mentioned wanting a causal filter specifically). The tradeoff is that if you have very "difficult" constraints, an IIR filter can become unstable, so keep that in mind. In practice you can implement a causal state filter by initializing the "future" values at the start to be zero (or some informed prior value).

Using filterdesigner/FDAtool - setting parameters in the GUI and ge... (2024)
Top Articles
What Happens To The Criminally Insane, After Court
Not Guilty by Reason of Insanity
Joe Taylor, K1JT – “WSJT-X FT8 and Beyond”
Dunhams Treestands
Skycurve Replacement Mat
Restored Republic January 20 2023
Blanchard St Denis Funeral Home Obituaries
Workday Latech Edu
Call Follower Osrs
His Lost Lycan Luna Chapter 5
Gameplay Clarkston
More Apt To Complain Crossword
Sinai Web Scheduler
Oppenheimer & Co. Inc. Buys Shares of 798,472 AST SpaceMobile, Inc. (NASDAQ:ASTS)
270 West Michigan residents receive expert driver’s license restoration advice at last major Road to Restoration Clinic of the year
Cape Cod | P Town beach
Spartanburg County Detention Facility - Annex I
Nene25 Sports
5 high school volleyball stars of the week: Sept. 17 edition
Kountry Pumpkin 29
Sulfur - Element information, properties and uses
Project, Time & Expense Tracking Software for Business
Noaa Duluth Mn
Vegito Clothes Xenoverse 2
Ford F-350 Models Trim Levels and Packages
Panolian Batesville Ms Obituaries 2022
Slim Thug’s Wealth and Wellness: A Journey Beyond Music
Www Va Lottery Com Result
Top 20 scariest Roblox games
2015 Kia Soul Serpentine Belt Diagram
Speechwire Login
Mjc Financial Aid Phone Number
Japanese Emoticons Stars
Progressbook Newark
Ugly Daughter From Grown Ups
Jeep Cherokee For Sale By Owner Craigslist
2024 Coachella Predictions
Avance Primary Care Morrisville
Austin Automotive Buda
Wsbtv Fish And Game Report
Banana Republic Rewards Login
Thelemagick Library - The New Comment to Liber AL vel Legis
All Characters in Omega Strikers
Kent And Pelczar Obituaries
Iman Fashion Clearance
CrossFit 101
Syrie Funeral Home Obituary
Adams-Buggs Funeral Services Obituaries
Michaelangelo's Monkey Junction
Craigslist Psl
Edict Of Force Poe
Kindlerso
Latest Posts
Article information

Author: Arline Emard IV

Last Updated:

Views: 5569

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Arline Emard IV

Birthday: 1996-07-10

Address: 8912 Hintz Shore, West Louie, AZ 69363-0747

Phone: +13454700762376

Job: Administration Technician

Hobby: Paintball, Horseback riding, Cycling, Running, Macrame, Playing musical instruments, Soapmaking

Introduction: My name is Arline Emard IV, I am a cheerful, gorgeous, colorful, joyous, excited, super, inquisitive person who loves writing and wants to share my knowledge and understanding with you.