Code covered by the BSD License  

Highlights from
Spectral Mask Tests

from Spectral Mask Tests by Mike Donovan
Test whether a filter's magnitude response fits within a spectral mask.

Using FilterMaskFigure.m

Using FilterMaskFigure.m

In a lot of filter design problems you are trying to design a filter so that the magnitude response of the filter fits within a specified mask. FilterMaskFigure.m is a program that plots the magnitude response of a filter that you've designed and overlays a spectral mask on the plot. This is an example of how to use FilterMaskFigure.m to test whether a filter that you've designed fits within a spectral mask.

This example and FilterMaskFigure.m use commands from MATLAB and the Signal Processing Toolbox.

Contents

Design a filter

b and a are the filter's numerator and denominator coefficients.

[b,a] = fir1(15,0.125);

Define the mask

f is a vector containing the frequency axis, normalized between 0 and 1. m is a vector containing the desired magnitudes in dB. The only known restriction here is that the f and m vectors need to be the same length.

f=[0 0.1 0.25 0.35 0.35 0.5 0.5 1];
m=[0 0  -15 -35 -40 -40 -60 -60];

Call FilterMaskFigure.m

FilterMaskFigure.m will take the input filter coefficients and specifications for the spectral mask and perform a test to make sure that the filter's magnitude response falls within the limits of the mask. A PASS or FAIL indication will be printed on the final plot.

FilterMaskFigure(b, a, f, m)
pass =
     1

Credit where credit is due

I used the Generate M-File feature from the MATLAB 7 PlotTools to create most of the code for FilterMaskFigure.m. I started with a plot created by the freqz(b,a) command, edited that plot with the new PlotTools, and then generated code for the figure when I had it in a format I liked. That was much easier for me than trying to write plotting commands by hand.

Don't forget M-Lint

Another good MATLAB 7 feature that I used after I had some working code was the M-Lint code checker. It found several lines of code in FilterMaskFigure.m that could be improved. One example is the line of code that's commented out on Line 64. I never would have found this better way to use the FIND command on my own.

Contact us at files@mathworks.com