Table of contents
FIR Frequency Sampling Structure
FIR Frequency Sampling Structure
Frequency sampling is a structural method of the FIR filter, in which the parameters describing the FIR filter are the parameters of the desired frequency response, not the impulse response . In order to obtain the parameters of the frequency sampling structure, we need to specify the required frequency response by equally spaced frequency sampling.
We can use the functions in MATLAB to realize its specific operations. Here we mainly use the fir1 function or fir2 function in MATLAB.
fir1 function
The fir1 function is a toolbox function for designing linear-phase FIRDFs using the window function method to realize the standard window function method design of linear-phase FIRDFs.
b=fir1(n,wn);
b=fir1(n,wn,'ftype');
b=fir1(n,wn,'ftype',window);
Among them, the parameter is the filter coefficient, the parameter is the filter order, and the parameter is the value of the cutoff frequency, and the value range must be .
Before sampling, we first need to normalize the frequency, because the normalized frequency is used when using the fir1 function for filter design. Let the actual sampling frequency be , the actual cutoff frequency be , let the normalized cutoff frequency be , . When designing bandpass and bandstop filters, , .
Take the design of a 48-order filter as an example:
fs=3200;%采样频率
fs_half=fs/2;%归一化频率
f1=45/fs_half;f2=55/fs_half;
b = fir1(48,[f1 f2]);%设计滤波器
[H w]=freqz(b,1,512);%求频响
[b_new,a_new]=invfreqz(H,w,48,0);
figure;freqz(b,1,512);
figure;freqz(b_new,1,512);
fir2 function
The fir2 function can be used to design windowed FIR filters with arbitrary frequency responses, and the fir1 function can be used for the design of standard low-pass, band-pass, high-pass and band-stop filters.
The various forms of function fir2 are as follows:
b = fir2(n,f,m)
b = fir2(n,f,m,window)
b = fir2(n,f,m,npt)
b = fir2(n,f,m,npt,window)
b = fir2(n,f,m,npt,lap)
b = fir2(n,f,m,npt,lap,window)
Next, the parameters in the fir2 function are introduced, which is the order of the filter. The vector is the amplitude response sample at the specified frequency point, and the frequency segment it divides corresponds to the amplitude response sample defined by the parameter; and has the same length, and the first and last components of the vector are 0 and 1 respectively; they can be centered The frequency point is copied, so as to jump to approach the amplitude response index. f: Specifies the normalized boundary frequency of each frequency band, increasing from 0 to 1, 1 corresponds , that is,
the number of grid points of the frequency response obtained by specifying the fir2 function for interpolation must be greater than half of the filter order, that is , the The default value of the parameter is 512.
specifies the size of the region to interpolate between repetition frequency points in f.
For example, to design a 30-order FIR filter, the code is as follows:
f = [0 0.6 0.6 1]; m = [1 1 0 0];
b = fir2(30,f,m);
[h,w] = freqz(b,1,128);
plot(f,m,w/pi,abs(h))
legend(‘Ideal’,‘fir2 Designed’)
title(‘Comparison of Frequency Response Magnitudes’)
Give another example. Design a 60-order FIR filter with the fir2 function, requiring the amplitude response of the filter 0 to π/4 to be 0, the amplitude response of π/4 to π/2 to be 1/4, and the amplitude of π/2 to 3π/4 The response is 0, and the magnitude response from 3π/4 to 1 is 1. The procedure is as follows:
n=60;
f=[0 0.25 0.25 0.50 0.50 0.75 0.75 1];
m=[0 0 1/4 1/4 0 0 1 1];
%对幅频响应插值时插值点的个数
npt=1024;
%插值时不连续点转变成连续时的点数 lap=50; %衰减为30dB的切比雪夫窗函数
window=chebwin(61,30);
b=fir2(n,f,m,npt,lap,window);