# Scaling of Filter Coefficients in "fir1" function

5 views (last 30 days)
Farshad Bolouri on 30 May 2024
Commented: Farshad Bolouri on 30 May 2024
Hello Everyone,
I was looking through the "fir1" function's implementation to see how the coeffs are being scaled. I came across this function:
function b = scalefilter(b,First_Band,ff,L)
%SCALEFILTER Scale filter to have passband approx. equal to one.
if First_Band
b = b / sum(b); % unity gain at DC
else
if ff(4)==1
% unity gain at Fs/2
f0 = 1;
else
% unity gain at center of first passband
f0 = mean(ff(3:4));
end
b = b / abs( exp(-1i*2*pi*(0:L-1)*(f0/2))*(b.') );
end
end
Since there is no documentation for this particular line, I was curious to know where the following equation comes from:
scalingFactor = 1 / abs( exp(-1i*2*pi*(0:L-1)*(f0/2))*(b.') );
Does anyone know?

Paul on 30 May 2024
Edited: Paul on 30 May 2024
For a FIR filter
H(z) = b0 + b1*z^-1 + b2*z^-2 .... + b_n*z^(n-1)
its frequency response is
H(w) = b0 + b1(exp(-1j*w) + b2*exp(-1j*w)^2 + .... b_n*exp(-1j*w)^(n-1)
where w is has units of rad/sample.
The equation of interest is computing abs(H(w0)) where w0 (rad/sample) is the middle of pass band. Recall that on input to fir1 the frequencies are normalized such that Wn = 1 -> w = pi. So if f0, which is derived from Wn, is the middle of the pass band, it's related to w0 by: w0 = pi*f0. I'm not sure why it's coded with a mutliply by 2 followed by a divide by 2. I guess it can be viewed as f0/2 converts the input frequency to cycles/sample and then the multiply by 2*pi converts to rad/sample.
Farshad Bolouri on 30 May 2024
Thank You @Paul !
Makes sense now.

### Categories

Find more on Signal Generation and Preprocessing in Help Center and File Exchange

R2024a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!