Digital Signal Processing using Matlab 5.3
     <<Home Lab 9                                    (Design of FIR Filters)
   

a) Optimal Method 

The signal processing in MATLAB (Matrix Lab) contains a number of design programs and functions for designing optimal FIR filters based on Remez and other algorithms. The Remez command is the key command for calculating FIR coefficients via the optimal method.

 A linear phase band pass filter                                                                                                                                                                                                                                                       

Example 1                                                                                                                                  

 A linear phase band-pass filter is required to meet the following specifications:

Passband                        900 - 1100 Hz

Passband ripple             < 0.87 dB      (take any value less than 0.87)

Stopband frequency     > 30dB (take any value greater than 30)

sampling frequency      15kHz

Transition frequency    450 Hz.

Use the optimal method to obtain suitable coefficients. Plot the magnitude and phase spectrum, Filter  length is 41.

 Solution                                                                                                                                    

Fs =15000;     %Sampling frequency

N=41;   %Length of filter

M=[0 0 1 1 0 0]; % Desired response (at 900 and 1100Hz)

F=[0 450/7500 900/7500 1100/7500 1550/7500 7500/7500]; % Normalized bandedge frequencies (F/Fs)

W=[3.33 1 3.33]; % weight vector (refer class work )

B=remez(N-1, F, M, W);   % filter coefficients

[H,f]=freqz(B,1,1024,Fs);

H1=abs(H);

mag=20*log10(H1);

plot(f,mag); grid;

Xlabel('Frequency (Hz)');

Ylabel('Magnitude(dB)');

figure;

phase=angle(H);

plot(f,phase); grid

 Result                                                                                                                                       

                                   

 

Frequency  response is observed at about 450 - 1650Hz, rather than 900 - 1100 Hz because of 450Hz transition frequency.

                                

 A linear phase band-pass filter                                                                                                   

                                                                                                                                                  

Example 2                                                                                                                                  

 A linear phase bandpass filter is required to meet the following specifications:

Passband                             12-16 kHz

Transition width                 2kHz

Pass-band ripple                 1 dB

Stop-band attenuation       45 dB

Sampling frequency           50 kHz

Estimate the filter length , N, and use the optimal method to determine the filter coefficients and hence plot the magnitude-frequency response. Compute the pass and stop-band ripples of the filter with the specified values.

 Solution                                                                                                                                    

fs=50000;

ap=1;

as=45;

m=[0 1 0]

F=[10000 12000 16000 18000];

dp=(10^(ap/20)-1)/(10^(ap/20)+1);

ds=10^(-as/20);

dev=[ds dp ds];

[N1, f0, m0, w]=remezord(F,m,dev,fs);

b=remez(N1-1,f0,m0,w);

[H,f] = freqz(b,1,1024,fs);

mag = 20*log10(abs(H));

plot(f,mag)

xlabel('Frequency (Hz)')

ylabel('Magnitude (dB)')

grid

Result                                                                                                                                       

                                     

 FIR low-pass digital filter                                                                                                           

                                                                                                                                                  

Exercise 1                                                                                                                                  

  An FIR low-pass digital filter is required to meet the following characteristics:

Stop-band edge frequency                > 40 dB

Pass-band edge frequency                100 Hz

Pass-band ripple                                 < 0.05 dB

Transition width                                 10 Hz

Sampling frequency                           1024 Hz

Calculate and list the coefficients of the filter using the optimal method. Sketch magnitude response of the filter.

 Solution                                                                                                                                    

    

 Result                                                                                                                                       

 

 FIR low-pass digital filter                                                                                                           

                                                                                                                                                  

Exercise 2                                                                                                                                  

  An FIR low-pass digital filter is required to meet the following characteristics:

Pass-band                                            12 - 16 kHz

Transition width                                 3 kHz

Sampling frequency                           96 kHz

Pass-band ripple                                 0.01 dB

Stop-band ripple                                 80 dB

Calculate and list the coefficients of the filter using the optimal method. Sketch magnitude response of the filter. Also estimate the filter length.

 Solution                                                                                                                                    

    

 Result                                                                                                                                       

 

  A digital FIR notch filter                                                                                                            

                                                                                                                                                  

Exercise 3                                                                                                                                  

  A digital FIR notch filter satisfying the specifications given below is required.

Lower pass-band                    0 to 0.21

Notch frequency                     0.25

Upper pass-band                    0.29 to 0.5

Pass-band deviation              0.00115

Stop-band deviation              0.001

 Solution                                                                                                                                    

    

 Result                                                                                                                                       

 


b) Frequency Sampling Method:

The  fir2 command is used to design FIR filters with arbitrary frequency response characteristics such as those encountered in the frequency sampling method


 Coefficients of the filter                                                                                                              

                                                                                                                                                  

Example 3                                                                                                                                  

 

 Solution                                                                                                                                    

    

 Result                                                                                                                                       

 

 

 HELP                                                                                                                                       

 PLOT                                                                                                                                        

 PLOT Linear plot.
PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y) disconnected points are plotted.

 STEM                                                                                                                                      

STEM Discrete sequence or "stem" plot.
STEM(Y) plots the data sequence Y as stems from the x axis terminated with circles for the data value.
STEM(X,Y) plots the data sequence Y at the values specified in X.

 SAWTOOTH                                                                                                                              SAWTOOTH Sawtooth and triangle wave generation.
SAWTOOTH(T) generates a sawtooth wave with period 2*pi for the elements of time vector T. SAWTOOTH(T) is like SIN(T), only it creates a sawtooth wave with peaks of +1 to -1 instead of
a sine wave.
SAWTOOTH(T,WIDTH) generates a modified triangle wave where WIDTH, a scalar parameter between 0 and 1, determines the fraction between 0 and 2*pi at which the maximum occurs. The function increases from -1
to 1 on the interval 0 to WIDTH*2*pi, then decreases linearly from 1 back to -1 on the interval WIDTH*2*pi to 2*pi. Thus WIDTH = .5 gives you a triangle wave, symmetric about time instant pi with peak amplitude
of one. SAWTOOTH(T,1) is equivalent to SAWTOOTH(T).
Caution: this function is inaccurate for huge numerical inputs

 SQUARE                                                                                                                                 

  SQUARE Square wave generation.
SQUARE(T) generates a square wave with period 2*Pi for the elements of time vector T. SQUARE(T) is like SIN(T), only it creates a square wave with peaks of +1 to -1 instead of a sine wave.
SQUARE(T,DUTY) generates a square wave with specified duty cycle. The duty cycle, DUTY, is the percent of the period in which the signal is positive.
For example, generate a 30 Hz square wave:
t = 0:.0001:.0625;
y = SQUARE(2*pi*30*t);, plot(t,y)

 ONES                                                                                                                                      

ONES Ones array.
ONES(N) is an N-by-N matrix of ones.
ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones.
ONES(M,N,P,...) or ONES([M N P ...]) is an M-by-N-by-P-by-... array of ones.
ONES(SIZE(A)) is the same size as A and all ones.

 SINC                                                                                                                                       

 SINC Sin(pi*x)/(pi*x) function.
SINC(X) returns a matrix whose elements are the sinc of the elements of X, i.e.
y = sin(pi*x)/(pi*x) if x ~= 0
    = 1                         if x = = 0
where x is an element of the input matrix and y is the resultant output element.

 RECTPULS                                                                                                                             

RECTPULS Sampled aperiodic rectangle generator.
RECTPULS(T) generates samples of a continuous, aperiodic, unity-height rectangle at the points specified in array T, centered about T=0. By default, the rectangle has width 1. Note that the interval of non-zero amplitude is defined to be open on the right,
i.e., RECTPULS(-0.5)=1 while RECTPULS(0.5)=0.

RECTPULS(T,W) generates a rectangle of width W.
 TRIPULS                                                                                                                                   

 TRIPULS Sampled aperiodic triangle generator.
TRIPULS(T) generates samples of a continuous, aperiodic, unity-height triangle at the points specified in array T, centered about T=0. By default, the triangle is symmetric and has width 1.

TRIPULS(T,W) generates a triangle of width W.

TRIPULS(T,W,S) allows the triangle skew S to be adjusted. The skew parameter must be in the range -1 < S < +1, where 0 generates a symmetric triangle.


DSP Lab 1   DSP Lab2   DSP Lab 3   DSP Lab4   DSP Lab 5   DSP Lab 6   DSP Lab7  DSP Lab8  DSP Lab9  DSP Lab10    Other material


   
 
                                                                                                                   <<Home
  
Ziauddin Siddiqui, B02ME CSN 07, Mehran University Of Engineering & Technology
Jamshoro, Sindh.
Email. [email protected]

1