Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How can i use filters created with Fdatool?

Subject: How can i use filters created with Fdatool?

From: Alessio Nervi

Date: 21 Jan, 2011 11:19:04

Message: 1 of 2

Hello!

I created a bandpass filter with Fdatool ( I omit the details of the filter).

I have to export the filter in the workspace, because I would use it to filter noise.
My idea was to export it as an Object, and after filtering the noise in this way:

%noise
x=rand(dim,1);

%filter
y=filter(Object_name, x);

It is correct this procedure?

Another question: I wanted to generate an M-file from the filter, How could I apply it to the noise?

Thanks in advance for the Help

Alessio

Subject: How can i use filters created with Fdatool?

From: Wayne King

Date: 21 Jan, 2011 11:38:04

Message: 2 of 2

"Alessio Nervi" <alessio.gastaldo@gmail.com> wrote in message <ihbq38$cng$1@fred.mathworks.com>...
> Hello!
>
> I created a bandpass filter with Fdatool ( I omit the details of the filter).
>
> I have to export the filter in the workspace, because I would use it to filter noise.
> My idea was to export it as an Object, and after filtering the noise in this way:
>
> %noise
> x=rand(dim,1);
>
> %filter
> y=filter(Object_name, x);
>
> It is correct this procedure?
>
> Another question: I wanted to generate an M-file from the filter, How could I apply it to the noise?
>
> Thanks in advance for the Help
>
> Alessio

Hi Alessio, Yes, if you have exported the filter to the workspace as a filter object, use filter() as you have written above. You also had the option of exporting the filter coefficients, in which case the syntax for filter() would be slightly different.

If you "generate MATLAB code" for your filter, you will get an .m file with the commands to construct your filter object at the command line with the specifications you have used in fdatool. For example:

Fpass = 9600; % Passband Frequency
Fstop = 12000; % Stopband Frequency
Apass = 0.5; % Passband Ripple (dB)
Astop = 60; % Stopband Attenuation (dB)
match = 'stopband'; % Band to match exactly

% Construct an FDESIGN object and call its BUTTER method.
h = fdesign.lowpass(Fpass, Fstop, Apass, Astop, Fs);
Hd = design(h, 'butter', 'MatchExactly', match);

Then you would just use filter as you have indicated above

y = filter(Hd,data);

If you are going to use your filter in a MATLAB program, I would not include the above code in that program because you are wasting a lot of computation redesigning the filter you've already designed. Just save the filter object and load that in your MATLAB program before you filter data.

Wayne

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us