Butterworth Filter-LPF, HPF, BPF

Butterworth Filter Design-LPF, HPF, BPF

  • Butterworth Low Pass Filter
  • Butterworth High Pass Filter
  • Butterworth Band Pass Filter


Logic and MATLAB Functions used

The MATLAB signal processing toolbox provides many useful functions for the design and analysis of classical digital IIR filters ( eg. Butterworth, chebyshev type 1 and 2nd and elliptic filters) for a given set of specifications ( eg. pass and stopband edge frequencies, pass band ripples and stopband attenuation ).

For a classical digital IIR filters, the steps involved in designing may be summarized as follows:

1) Specify the desired filter

2) Determine a suitable analog prototype lowpass filter with, eg.butterworth, chebyshev type 1, chebyshev type 2 or elliptic characteristics.

3) Transform the prototype analog filter to create a low-pass, highpass, bandpass or bandstop filter.

4) Convert the transformed filter into an equivalent discrete time filter (for example, using impulse invariant or the bilinear z-transform method).

The MATLAB signal processing toolbox provides a number of high level functions for carrying out steps 2 to 4 simultaneously or separately. For example, the syntax for the MATLAB command to create a lowpass, highpass, bandpass, or bandstop filter with a butterworth characteristic is (step 1 and step 2):

[b,a]=butter (N,Wc,options)

[z,p,k]=butter(N,Wc,options)

The first command calculates the numerator and denominator coefficients Nth order discrete time butterworth filter with a 3dB cutoff frequency (or band edge frequency), Wc-->normalized to Nyquist frequency. The numerator and denominator coefficients of the filter are returned in the vectors 'b' and '0' respectively in ascending -ve powers of z.

If the word 'options' is left out the commands defaults to a low pass filter(unless Wc is a vector of frequencies , in which case it defaults to a badpass filter). For high pass and bandstop filters the words 'high' and 'stop' are used as options. Foe bandpass and bandstop filters Wc is is a two element vector that specifies the cutoff (or bandedge )frequencies: Wc=[Wc1, Wc2]

Where Wc1

The second command returns the positions of the zeroes and poles, in tangular form, in z and p and filter gain k.

One more command that is most useful is:

[N,Wc]=buttord(Wp,Ws,Ap,As);

Where Wp-->passband edge frequency

Ws-->stopband edge frequency

Ap-->passband attenuation

As-->stopband attenuation

N-->order of the filter

Wc-->cutoff frequency of the filter

Similar commands exist for other classical filters types also.


Algorithm

1. Input sampling frequency of the filter to be designed.

1. Input passband attenuation.

3. Input stopband attenuation.

4. Input stopband attenuation.

5. IOnput stopband edge frequency.

6. By inputting maximum frequency that will be used in filter, calculate nyquist frequency of the passband and stopband edge frequencies; or you normalizes the frequencies.

7. Find order N and cutoff frequency Wc using "buttord" command.

8. Find zeroes and poles (i.e. find the tranfer function roots for numerator and denominator) using "butter" command

9. Find numerator and denominator polynomials(i.e. transfer functions) using "butter" command(steps 8 and 9 are interchangeable)

10. Plot the frequency response using "freqz" command

11. Plot pole-zero diagram using "zplane" command


PROGRAM

%butterworth Lowpass Filter

%Input Part

fs=input('Enter the sampling frequency');

Ap=input('enter the passband attenuation')

As=input('enter the stopband attenuation')

Wpm=input ('Enter the maximum usable frequency')

Wp1=input('enter passband edge frequency')

Wp=Wp1/Wpm %Nyquist frequency

ws1=input('Enter the stopband edge frequency')

ws=ws1/wpm %Nyquist frequency

[N,Wc]=buttord(buttord(wp, ws, Ap, As); %find order and cutoff frequency

[z,p,k]=butter(n,Wc); %find zeroes, poles and gain factor

%'option' is blank==>lowpass filter

[b,a]=butter(N,Wc); %find tranfer function

%plotting frequency response and pole-zero graphs

subplot(2,2,1);

[h,f]=freqz(b,a,fs/2,fs); %find frequency response

plot(f,abs(h)); %plot magnitude response

xlabel('frequency in Hz');

ylabel('Magnitude');

subplot(2,2,2);

plot(f,ang(h));%plot phase plot

xlabel('Frequency in Hz');

ylabel('Phase angle');

subplot(2,2,3);

zplane(b,a); %plot pole-zero diagram


Butterworth Highpass filter

The program is same as above;but use 'high' in the place of 'options'(which is blank in LPF)


Butterworth Bandpass Filter

%input part

fs=input('Enter the sampling frequency');

Ap=input('enter the passband attenuation');

As=input('enter the stopband attenuation');

Wpm=input ('Enter the maximum usable frequency');

Wp1=input('enter passband edge frequency');

Wp2=input('Enter the upper passband edge frequency');

Wp=(Wp1/Wpm,wp2/wpm); %Nyquist frequency

ws1=input('Enter the stopband edge frequency')

ws2=input('Enter the upper stopband edge frequency')

ws=(ws1/wpm,ws2/wpm); %Nyquist frequency

%processing part

[N,Wc]=buttord(wp, ws, Ap, As); %find order and cutoff frequency

[z,p,k]=butter(n,Wp); %find zeroes, poles and gain factor

[b,a]=butter(N,Wp); %find tranfer function

%wp is two element vector

%'option' is blank==>bandpass filter

%Plotting frequency response and pole-zero graphs

[h,f]=freqz(b,a,fs/2,fs); %find frequency response

subplot(2,2,1);

plot(f,abs(h)); %plot magnitude response

xlabel('frequency in Hz');

ylabel('Magnitude----------------->');

subplot(2,2,2);

plot(f,ang(h));%plot phase plot

xlabel('Frequency in Hz');

ylabel('Phase angle------------->');

subplot(2,2,3);

zplane(b,a); %plot pole-zero diagram



Butterworth Bandstop Filter:

Use 'stop' in the place of 'option' in the command “butter.”

2 comments:

  1. Thank so much. The above matlab expressions was clealy explained. It is very useful to have a clear idea about the implementation butterworth filter. Now i can do further improvement as well as teach to my friends. Thanks again

    ReplyDelete
  2. plz can u help me same code for verilog?


    ReplyDelete

Your Comments... (comments are moderated)