b = firls(n,f,a)
returns row vector b containing the n+1 coefficients
of the order n FIR filter. This filter has frequency-amplitude
characteristics approximately matching those given by vectors, f and a.

b = firls(n,f,a,w) uses
the weights in vector w, to weigh the error.

The following shows how to design a 24th-order
anti-symmetric filter with piecewise linear passbands, and plot the
desired and actual amplitude responses.

Create the frequency and amplitude vectors, f and a.

f = [0 0.3 0.4 0.6 0.7 0.9];
a = [0 1 0 0 0.5 0.5];

Use firls to obtain the 25 coefficients
of the filter.

b = firls(24,f,a,'hilbert');

Plot the ideal amplitude response along with the transition
regions.

plot(f.*pi,a,'o','markerfacecolor',[1 0 0]);
hold on;
plot(f.*pi,a,'r--','linewidth',2);

Use freqz to obtain the frequency response
of the designed filter and plot the magnitude response of the filter.

Order of the filter, specified as an integer scalar. For odd
orders, the frequency response at the Nyquist frequency is necessarily
0. For this reason, firls always uses an even filter
order for configurations with a passband at the Nyquist frequency.
If you specify an odd-valued n, firls increments
it by 1.

Pairs of frequency points, specified as a vector of values ranging
between 0 and 1, where 1 corresponds to the Nyquist frequency. The
frequencies must be in increasing order, and duplicate frequency points
are allowed. You can use duplicate frequency points to design filters
exactly like those returned by the fir1 and fir2 functions with a rectangular (rectwin) window.

f and a are the same length.
This length must be an even number.

Amplitude values of the function at each frequency point, specified
as a vector of the same length as f. This length
must be an even number.

The desired amplitude at frequencies between pairs of points
(f(k), f(k+1))
for k odd, is the line segment connecting the
points (f(k), a(k))
and (f(k+1), a(k+1)).

The desired amplitude at frequencies between pairs of points
(f(k), f(k+1))
for k even is unspecified. These are transition
or "don't care" regions.

Weights to weigh the fit for each frequency band, specified
as a vector of length half the length of f and a,
so there is exactly one weight per band. w indicates
how much emphasis to put on minimizing the integral squared error
in each band, relative to the other bands.

Filter coefficients, returned as a numeric vector of n+1 values,
where n is the filter order.

b = firls(n,f,a) designs a linear-phase filter
of type I (n odd) and type II (n)
. The output coefficients, or "taps," in b obey
the relation:

b(k) = b(n+2-k), k = 1, ... , n + 1

b = firls(n,f,a,'hilbert') designs a linear-phase
filter with odd symmetry (type III and type IV). The output coefficients,
or "taps," in b obey the relation:

b(k)
= –b(n+2-k), k = 1, ... , n + 1

b = firls(n,f,a,'differentiator') designs
type III and type IV filters, using a special weighting technique.
For nonzero amplitude bands, the integrated squared error has a weight
of (1/f)^{2}. This weighting causes the error
at low frequencies to be much smaller than at high frequencies. For
FIR differentiators, which have an amplitude characteristic proportional
to frequency, the filters minimize the relative integrated squared
error. This value is the integral of the square of the ratio of the
error to the desired amplitude.

One of the following diagnostic messages is displayed when an
incorrect argument is used:

F mustbeevenlength.
F andAmustbeequallengths.
Requires symmetrytobe'hilbert'or'differentiator'.
Requires oneweightperband.
Frequencies inFmustbenondecreasing.
Frequencies inFmustbeinrange[0,1].

A more serious warning message is

Warning: Matrix is closetosingularorbadlyscaled.

This tends to happen when the product of the filter length and
transition width grows large. In this case, the filter coefficients
b might not represent the desired filter. You can check the filter
by looking at its frequency response.

firls designs a linear-phase FIR filter.
This filter minimizes the weighted, integrated squared error between
an ideal piecewise linear function and the magnitude response of the
filter over a set of desired frequency bands.

Reference [1] describes the theoretical
approach behind firls. The function solves a system
of linear equations involving an inner product matrix of size roughly n/2 using
the MATLAB^{®} \ operator.

This function designs type I, II, III, and IV linear-phase filters.
Type I and II are the defaults for n even and odd respectively. The 'hilbert' and 'differentiator' flags
produce type III (n even) and IV (n odd) filters. The various filter
types have different symmetries and constraints on their frequency
responses (see [2] for
details).

Linear Phase Filter Type

Filter Order

Symmetry of Coefficients

Response H(f), f = 0

Response
H(f), f = 1 (Nyquist)

Type I

Even

b(k) = b(n+2-k), k=1,..., n+1

No restriction

No restriction

Type II

Even

b(k) = b(n+2-k), k=1,..., n+1

No restriction

H(1) = 0

Type III

Odd

b(k) = –b(n+2-k), k=1,..., n+1

H(0) = 0

H(1) = 0

Type IV

Odd

b(k) = –b(n+2-k), k=1,..., n+1

H(0) = 0

No restriction

References

[1] Parks, T.W., and C.S. Burrus, Digital
Filter Design, John Wiley & Sons, 1987, pp. 54-83.

[2] Oppenheim, A.V., and R.W. Schafer, Discrete-Time
Signal Processing, Prentice-Hall, 1989, pp. 256-266.