Hello, I'm currently taking an Electrical Engineering class but I'm a
Mathematics Graduate student so I'm missing some of the screws that put this
whole shebang together so I'm having some trouble with some probably very basic
things for all of you. Anyways, I'm trying to construct 7 butterworth bandpass
filters but they're not coming out how I want them to. I'm used to using the
fir1 filter and I can do that but there's a difference with the butterworth
filters that I can't figure out why it doesn't work. For example: I type in this
to create a bandpass filter centered at 697 Hz:

but the frequency plot doesn't show this. Also, how do you apply a butterworth
filter to a signal? Usually with the fir1 filter I just convoluted the impulse
response with the signal directly but the butterworth filter gives me 2 sets of
coefficients I don't know how to use. Any help would be appreciated :)

Posted by Jeff Winter●November 3, 2005

Hi,

If you have the signal processing toolbox, try using the fdatool (type help
fdatool at the Matlab prompt for more detail). This tool makes things a lot
easier.

With Butterworth (as with other filters, not just analog ones) you should
first specify your filter design. This should include passband and stopband
frequencies and attenuation levels.

Using your example of a bandpass filter (I have extended it a little).

% Design a bandpass filter with passband of 692 Hz to 702 Hz, with less than
3 dB of ripple in the passband, and %40 dB attenuation in the stopbands that
are 50 Hz wide on both sides of the passband. The sampling frequency is %
8kHz:

% Calculate the minimum order of Butterworth filter required to meet the
filter design specifications
[n,Wn] = buttord(Wp,Ws,Rp,Rs) % Where: n is the filter order and Wn the
normalised cut-off frequencies

% Design the Butterworth filter
[b,a] = butter(n,Wn);

% Plot the frequency response
% Freqz uses an FFT to estimate the frequency response. In this example
1024 is the size of the FFT used.
freqz(b,a,1024,Fs)
If you run this code in Matlab, you will see the filter order (n) is 2.
Where did you get an order of 50 from? If I take your code and reduce the
order to say 5, the result is more realistic.

In order to apply this filter design to a signal, simply use:

y = filter(b,a,X); % Where X is your input signal and y is the filtered
signal

This filters the data in vector X with the filter described by numerator
coefficient vector b and denominator coefficient vector a.
Hope this helps, good luck,

Jeff
************************************
Jeff Winter
Snr Signal Processing Engineer
Aeroflex
www.aeroflex.com
Check out our PXI RF digitizer:
www.aeroflex.com/pxi
-----Original Message-----
From: matlab@matl... [mailto:matlab@matl...]On Behalf Of
coolmemin@cool...
Sent: 03 November 2005 02:14
To: matlab@matl...
Subject: [matlab] Help using butterworth filters
Hello, I'm currently taking an Electrical Engineering class but I'm a
Mathematics Graduate student so I'm missing some of the screws that put this
whole shebang together so I'm having some trouble with some probably very
basic things for all of you. Anyways, I'm trying to construct 7 butterworth
bandpass filters but they're not coming out how I want them to. I'm used to
using the fir1 filter and I can do that but there's a difference with the
butterworth filters that I can't figure out why it doesn't work. For
example: I type in this to create a bandpass filter centered at 697 Hz:

but the frequency plot doesn't show this. Also, how do you apply a
butterworth filter to a signal? Usually with the fir1 filter I just
convoluted the impulse response with the signal directly but the butterworth
filter gives me 2 sets of coefficients I don't know how to use. Any help
would be appreciated :)

Posted by Jeff Winter●November 3, 2005

Hi,

If you have the signal processing toolbox, try using the fdatool (type help
fdatool at the Matlab prompt for more detail). This tool makes things a lot
easier.

With Butterworth (as with other filters, not just analog ones) you should
first specify your filter design. This should include passband and stopband
frequencies and attenuation levels.

Using your example of a bandpass filter (I have extended it a little).

% Design a bandpass filter with passband of 692 Hz to 702 Hz, with less than
3 dB of ripple in the passband, and %40 dB attenuation in the stopbands that
are 50 Hz wide on both sides of the passband. The sampling frequency is %
8kHz:

% Calculate the minimum order of Butterworth filter required to meet the
filter design specifications
[n,Wn] = buttord(Wp,Ws,Rp,Rs) % Where: n is the filter order and Wn the
normalised cut-off frequencies

% Design the Butterworth filter
[b,a] = butter(n,Wn);

% Plot the frequency response
% Freqz uses an FFT to estimate the frequency response. In this example
1024 is the size of the FFT used.
freqz(b,a,1024,Fs)
If you run this code in Matlab, you will see the filter order (n) is 2.
Where did you get an order of 50 from? If I take your code and reduce the
order to say 5, the result is more realistic.

In order to apply this filter design to a signal, simply use:

y = filter(b,a,X); % Where X is your input signal and y is the filtered
signal

This filters the data in vector X with the filter described by numerator
coefficient vector b and denominator coefficient vector a.
Hope this helps, good luck,

Jeff
************************************
Jeff Winter
Snr Signal Processing Engineer
Aeroflex
www.aeroflex.com
Check out our PXI RF digitizer:
www.aeroflex.com/pxi
-----Original Message-----
From: matlab@matl... [mailto:matlab@matl...]On Behalf Of
coolmemin@cool...
Sent: 03 November 2005 02:14
To: matlab@matl...
Subject: [matlab] Help using butterworth filters
Hello, I'm currently taking an Electrical Engineering class but I'm a
Mathematics Graduate student so I'm missing some of the screws that put this
whole shebang together so I'm having some trouble with some probably very
basic things for all of you. Anyways, I'm trying to construct 7 butterworth
bandpass filters but they're not coming out how I want them to. I'm used to
using the fir1 filter and I can do that but there's a difference with the
butterworth filters that I can't figure out why it doesn't work. For
example: I type in this to create a bandpass filter centered at 697 Hz:

but the frequency plot doesn't show this. Also, how do you apply a
butterworth filter to a signal? Usually with the fir1 filter I just
convoluted the impulse response with the signal directly but the butterworth
filter gives me 2 sets of coefficients I don't know how to use. Any help
would be appreciated :)

Posted by coolmemin@hotmail.com●November 2, 2005

Hello, I'm currently taking an Electrical Engineering class but I'm a
Mathematics Graduate student so I'm missing some of the screws that put this
whole shebang together so I'm having some trouble with some probably very basic
things for all of you. Anyways, I'm trying to construct 7 butterworth bandpass
filters but they're not coming out how I want them to. I'm used to using the
fir1 filter and I can do that but there's a difference with the butterworth
filters that I can't figure out why it doesn't work. For example: I type in this
to create a bandpass filter centered at 697 Hz:

but the frequency plot doesn't show this. Also, how do you apply a butterworth
filter to a signal? Usually with the fir1 filter I just convoluted the impulse
response with the signal directly but the butterworth filter gives me 2 sets of
coefficients I don't know how to use. Any help would be appreciated :)