Design and use of filters using fdatool in MATLAB
This article describes how to design and use a Filter Using fdatool in MATLAB.
1. Type fdatool in MATLAB to run the filter design and analysis tool. For more information, see Signal Processing Toolbox> fdatool in MATLAB help.
2. Several issues that should be paid attention to in the fdatool tool: (a) fstop (blocking band cutoff frequency) cannot be greater than or equal to the sampling frequency fs/2, which is determined by the design of the digital filter. (B) Export the designed filter in two ways: export the filter either as filter coefficients variables or as a dfilt or mfilt filter object variable. (For details, see Signal Processing Toolbox> fdatool> exporting a filter design in MATLAB help.
Export: file --- export: The Export Dialog Box is displayed. Set "export as" to "objects" and "varable names" to change. The default value is HD.
3. (a) If dfilt or mfilt filter object variable is exported, you can use [B, a] = TF (HD) to convert the dfilt filter object to the form of a transfer function, then use d = filter (B, A, x); to use this filter. Among them, filter is the default function, B and A are the transfer function parameters just designed, X is the original acquisition signal, and D is the filtered signal. X = importdata ('e: \ MATLAB _work \ XY \ BB \ o6.txt ');
N = length (x); % get Length
FS = 4000; % sampling frequency
T = (0: N-1)/Fs; Output HD;
[B, A] = TF (HD); % get the transfer function
D = filter (B, A, x); subplot (311); plot (t, x); Title ('original sign ');
Xlabel ('T ');
Ylabel ('y ');
Grid on;
MATLAB Design of Digital Filter Based on fdatool
MATLAB Design of Digital Filter
1.1 fdatool Interface Design
1.1.1 introduction to fdatool
Fdatool (Filter Design & Analysis Tool) is a specialized filter design and analysis tool in the MATLAB Signal Processing Toolbox. The filters design toolbox is also added in the versions above Matlab ). Fdatool can be used to design almost all basic conventional filters, including various design methods for fir and IIR. It is easy to operate, convenient and flexible.
The fdatool interface consists of two parts: design filter, which is used in the lower part of the interface to set the design parameters of the filter, and feature area, which is in the upper part of the interface, used to display various features of a filter. Design filter is mainly divided:
Filter Type options, including lowpass, highpass, bandpass, bandstop, and special FIR filters.
Design method options, including the Butterworth (Butterworth) method of the IIR filter, Chebyshev type I (Chebyshev I type) method, Chebyshev type II (Chebyshev II type) elliptic method, Equiripple method of FIR filter, least-squares method, and window function method.
The filter order option defines the order of the filter, including specify Order (specified order) and minimum order (minimum order ). Fill in the order of the filter to be designed in specify Order (n-order filter, specify order = N-1 ), if minimum order is selected, Matlab automatically uses the minimum order based on the selected filter type.
The frenquency specifications option defines the parameters of the frequency band, including the sampling frequency fs and the cutoff frequency of the frequency band. The specific options are determined by the filter type option and design method option. For example, the bandpass (band-pass) filter must define fstop1 (lower impedance cutoff frequency) and fpass1 (Lower Pass cutoff frequency) fpass2 and fstop2, while the lowpass filters only need to define fstop1 and fpass1. When using a window function to design a filter, the transition zone is determined by the type and order of the window function. Therefore, you only need to define the pass-through cutoff frequency, instead of the resistance parameter.
The magn1_specifications option that defines amplitude attenuation. For example, when designing a band-pass filter, you can define wstop1 (amplitude attenuation at the frequency fstop1), wpass (amplitude attenuation within the band range), and wstop2 (amplitude attenuation at the frequency fstop2 ). When the window function is designed, the amplitude attenuation at the cutoff frequency of the wildcard is fixed to 6 dB, so it is not required to be defined.
Window specifications option. This option can be defined when the window function design is adopted. It contains various window functions.
1.1.2 example of band-pass filter design
This article will take the design of a FIR filter as an example to illustrate how to use MATLAB to design a digital filter: inject a sine signal of HZ into the small current grounding system and trace and analyze it, it is required to design a passthrough digital filter to filter out the power frequency and the whole harmonic, so as to separate the injected signal from a very complex signal. Parameter requirements: 96-level FIR digital filter, sampling frequency 1000Hz, Hamming window function design.
In this example, select bandpass in filter type, select FIR window in design method, and select Hamming in window specifications; specify specify order = 95 in the filter order item. Because the window function design is adopted, as long as FC1 and FC2 are given, FC1 = 70Hz is selected, FC2 = 84Hz. Click design filter to obtain the designed FIR filter. Menu option analysis shows the amplitude frequency response, phase frequency response, zero pole configuration, and filter coefficient of the designed filter in the feature area. After the design is complete, save the result as an FDA document.
During the design process, the phase-frequency characteristics and design requirements of the filter can be compared, and the parameters and filter types can be adjusted at any time,
To get the best results. You can also use fdatool to design other types of FIR filters and IIR filters.
Figure 1 amplitude frequency and phase frequency response of a filter (feature zone)
Fig.1 magn1_response and phase response of the filter
1.2 programming Law
In Matlab, various filters are designed with the corresponding amplitude response calculation function [3], which can be used for the programming of filters.
The above example of the band-pass filter can be used in programming:
C = 95; % defines the 96-level filter order
W1 = 2 * pI * FC1/Fs;
W2 = 2 * pI * FC2/Fs; % parameter conversion, which converts the analog filter technical indicator to the digital filter technical indicator
Window = Hamming (C + 1); % use the Hamming Window Function
H = FIR1 (C, [W1/PI W2/PI], window); % use the pop-up window design function of the standard response FIR1
Freqz (H, 1,512); % digital filter Frequency Response
Run the program in the MATLAB environment to obtain the amplitude-frequency response curve and filter coefficient h of the filter. The length limit. The source program will not be listed in detail here.
2. Simulation
In this paper, the simulation block of digital filter is formed by calling the function module in the simulation. During the simulation process, you can double-click each function module and change the parameters at any time to obtain the simulation results in different States. For example, to construct the original signal based on the fundamental wave, import the filter file 1.fda2 designed by fdatool in 2.1.2 through the digital filter design (Digital Filter Design) module in the simulation environment. The simulation and filter 2 are shown.
Figure 2 simulation diagram and filtering of the simulation model in the chain
Fig.2 simulated connections and Waveform
We can see that the 83.3hz frequency component (scope1) is separated after discrete sampling and digital filtering ). The reason for choosing the above superimposed signal as the original signal is that in actual work, it is necessary to further perform band-pass filtering on the signal that has undergone differential filtering, and the signal components are basically the same, it can reflect the actual situation. The filter designed in this example has been applied in practical work and achieved good results.