design a symmetric filter in matlab

To design a symmetric filter in MATLAB, one can follow the below steps:

  1. Choose a filter type: There are various filter types, such as lowpass, highpass, bandpass, bandstop, etc. Choose a filter type based on the filter requirements.

  2. Determine the filter specifications: The filter specifications include the passband frequency, stopband frequency, passband ripple, stopband attenuation, etc. Specify the filter specifications based on the filter type and application.

  3. Design the filter: Use the fir1() or firls() function to design the filter. These functions can design various types of filters, including symmetric and asymmetric filters.

  4. Make the filter symmetric: If the filter is not symmetric, make it symmetric by averaging the coefficients. This can be done using the fliplr() and conv() functions.

Here's an example code to design a symmetric lowpass filter with passband frequency of 0.4pi and stopband frequency of 0.5pi:

main.m
% Filter specifications
fs = 1;     % Sampling frequency
fcuts = [0.4*pi 0.5*pi];     % Cutoff frequencies
mags = [1 0];     % Magnitudes at the cutoff frequencies
devs = [0.05 0.01];     % Maximum deviation from the ideal response

% Filter design
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fs);
b = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');

% Make the filter symmetric
bsym = conv(b,fliplr(b))/2;
406 chars
13 lines

In this code, the kaiserord() function is used to design a Kaiser windowed filter with the specified filter specifications. The fir1() function is used to generate the filter coefficients. Finally, the conv() function is used to make the filter symmetric, and the fliplr() function is used to flip the filter coefficients.

gistlibby LogSnag