WP file: firfilter1.wpd

%file: fir jbh Apr. 1, 2003 matlab

N =64; %no. of taps

b=fir1(N,1/2); %fir filter with N taps, cutoff freq 1/2 x fsample

%b has N+1 elements.

NFREQ=100;

pwr=zeros(1,NFREQ);

for FN=1:NFREQ

w=pi*(FN-1)/NFREQ;

pwr(FN)=0;

for i=1:N+1

for j=1:N+1

pwr(FN)=pwr(FN) + b(i)*b(j)*cos(w*(i-j));

end

end

pwr(FN)=10*log(pwr(FN))/log(10);

end

AXIS([0 NFREQ -100 10])

plot(pwr)

» help fir1

FIR1 FIR filter design using the window method.

B = FIR1(N,Wn) designs an N'th order lowpass FIR digital filter and returns the filter coefficients in length N+1 vector B.

The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. The filter B is real and has linear phase, i.e., even symmetric coefficients obeying B(k) = B(N+2-k), k = 1,2,...,N+1.

If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter with passband W1 < W < W2.

B = FIR1(N,Wn,'high') designs a highpass filter. B = FIR1(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2].

If Wn is a multi-element vector, Wn = [W1 W2 W3 W4 W5 ... WN], FIR1 returns an order N multiband filter with bands 0 < W < W1, W1 < W < W2, ..., WN < W < 1.

B = FIR1(N,Wn,'DC-1') makes the first band a passband.

B = FIR1(N,Wn,'DC-0') makes the first band a stopband.

For filters with a passband near Fs/2, e.g., highpass and bandstop filters, N must be even.

By default FIR1 uses a Hamming window. Other available windows, including Boxcar, Hanning, Bartlett, Blackman, Kaiser and Chebwin can be specified with an optional trailing argument. For example,

B = FIR1(N,Wn,kaiser(N+1,4)) uses a Kaiser window with beta=4.

B = FIR1(N,Wn,'high',chebwin(N+1,R)) uses a Chebyshev window.

By default, the filter is scaled so the center of the first pass band has magnitude exactly one after windowing. Use a trailing 'noscale' argument to prevent this scaling, e.g. B = FIR1(N,Wn,'noscale'),

B = FIR1(N,Wn,'high','noscale'), B = FIR1(N,Wn,wind,'noscale').

See also KAISERORD, FIRCLS1, FIR2, FIRLS, FIRCLS, CREMEZ,

REMEZ, FREQZ, FILTER.