filter.ascii
来自「speech signal process tools」· ASCII 代码 · 共 1,263 行 · 第 1/2 页
ASCII
1,263 行
ENTROPIC RESEARCH LABORATORYESPS APPLICATIONS NOTE: Filtering Sampled DataBrian Sublett and David BurtonRevised by: Derek LinEntropic Research Laboratory, Inc.600 Pennsylvania Ave., S.E. Suite 202Washington, DC 20003(202) 547-14201 . INTRODUCTION The Entropic Signal Processing System (ESPS) contains a variety of programs used in the digital filtering of sampled data. This document introduces the reader to programs that deal with filtering and illustrates their use through some common examples. Digital filters are characterized by their coefficients. In ESPS, these coefficients are usually stored in FEAFILT (5-ESPS) files. Programs that create FEAFILT (5-ESPS) files are called filter design programs. These are discussed in Section 2. Programs that use FEAFILT (5-ESPS) files to perform the digital filtering operation are called filtering programs, and Section 3 describes these programs. Finally, Section 4 discusses programs used to calculate and plot the frequency response or transfer function of the coefficients in a FEAFILT (5-ESPS) file.1 .1 . User Level Programs ESPS includes the following user level programs that support the filtering of sampled data. Each of these programs is described in this document.notch_filt (1-ESPS) - Design a second order notch filter.wmse_filt (1-ESPS)- Design a FIR filter with minimum weighted MS error.win_filt (1-ESPS) - Design a FIR filter by the Kaiser windowing method.pkmc_filt(1-ESPS) - Design a FIR filter by Parks-McClellan method.cb_filt (1-ESPS) - Design a FIR filter by constraint-based method.iir_filt (1-ESPS)- Design a Recursive (IIR) filter by various methods.xpz (1-ESPS) - Interactive Pole/Zero filter design.zero_pole (1-ESPS) - Convert ASCII zero and pole locations to an ESPS FEAFILT (5-ESPS) file.impulse_resp (1-ESPS) - Compute unit impulse responses of filters in FEAFILT (5-ESPS) file.atofilt (1-ESPS)- Convert ASCII files to an ESPS FEAFILT (5-ESPS) file.filter2 (1-ESPS)- Perform digital filtering on a sampled data file.fft_filter (1-ESPS)- Perform FIR digital filtering using frequency domain convolution.sfconvert (1-ESPS)- Converts sampling frequency in a sampled data file.filtspec (1-ESPS)- Generate spectral record file for specified records in a FEAFILT (5-ESPS) file.1 .2 . Library Functions The following ESPS library functions support the use of filters. Library functions are not discussed in this document. The user should refer to the appropriate Section 3 manual page for further help with filtering library functions.init_feafilt_hd (3-ESPS)- Initialize a FEA file header for subtype FEAFILE.allo_feafilt_rec (3-ESPS)- Allocate memory for a FEAFILT (5-ESPS) file record.block_filter2 (3-ESPS)- Filter data from a file or memoryget_feafilt_rec (3-ESPS)- Get the next data record from an ESPS FEAFILT (5-ESPS) file.interp_filt (3-ESPS)- Perform interpolation filtering on a data array.print_feafilt_rec (3-ESPS)- Print an ESPS FEAFILT (5-ESPS) record.put_feafilt_rec (3-ESPS)- Put an ESPS FEAFILT (5-ESPS) record into a file.pz_to_co (3-ESPS) - Convert pole or zero locations to filter coefficients.2 . FILTER DESIGN There are two kinds of filters often discussed in the literature and text books: finite impulse response (FIR) and infinite impulse response (IIR). FIR filters have only numerator coefficients, and are sometimes called moving-average or all-zero filters. IIR filters have denominator (and possibly numerator) coefficients, and are also called recursive filters. ESPS programs provide design support for both types of filters, and this section describes those programs that calculate filter coefficients and store them in FEAFILT (5-ESPS) files. These programs use ESPS parameter files as means of user interface. Typically such parameter files contain parameters such as sampling rate, desired band edges, values, and weighting factors, etc... In IIR filter design, four types of filter designs are available: lowpass, highpass, bandpass, and bandstop. Their bandedges are controlled by only 4 parameters. Eparam and xeparam(1-ESPS) may be used to invoke the IIR design program to prompt user for parameter values. In FIR filter design, however, N-band filter design is possible, and the number of parameters for bandedges, desired band values vary with N. Although eparam and xeparam(1-ESPS) can be invoked to prompt for parameter values, the default parameter file templates under the directory $ESPS_BASE/lib/params are pre-written and fixed to parameters applicable for either 2 or 3 band FIR filters. Therefore, customize these template parameter files to suit your needs. The cover shell script xfir_filt in the directory $ESPS_BASE/bin is a good example for interactive filter design tool based on ESPS parameter file processing and XIG interface. (See ESPS Application Notes: X Interface Generation in ESPS and xwaves+)2 .1 . notch_filt The program notch_filt (1-ESPS) designs a second order IIR filter that removes or "notches out" a narrow region in the frequency domain and passes all other frequencies. This is done by placing a zero on the unit circle in the Z-plane at a point corresponding to this notch frequency, and then placing a pole very close to it and just inside the unit circle. The complex conjugates of this pole and zero are also included to guarantee a filter with real coefficients. The frequency response will therefore be zero when evaluated at the zero frequencies, but nearly everywhere else on the unit circle, the effects of the poles and zeroes will cancel. To use notch_filt, the user must specify the sampling frequency, the notch frequency, the notch bandwidth, and, of course, the output file name. The notch bandwidth is defined as the distance (in the frequency domain) between the -6 dB. points on either side of the notch. The three critical frequencies may be specified on the command line or in a parameter file. If all three are specified on the command line, no parameter file is necessary.2 .1 .1 . notch_filt Example. To illustrate the use of notch_filt, a filter will be designed to remove 120 Hz noise from 8 kHz. sampled data. The notch bandwidth will be 20 Hz. The command for this is: notch_filt -s8000 -n120 -b20 notch120.filt The response for the resulting filter (in the file notch120.filt) is shown in Figure 2-1. The commands used to obtain the plot in Figure 2-1 are covered in Section 4.2 .2 . wmse_filt The program wmse_filt (1-ESPS) designs an FIR filter of specified length using the weighted mean-square-error criterion. The user specifies a desired frequency response and a weighting function and the program finds the set of filter coefficients whose response minimizes the mean square error with respect to the desired response, when weighted by the weighting function. In other words, for desired response D(f) and weighting function W(f), the program finds the coefficients of the filter H(f) which minimizes: If uniform weighting is used (i.e. W(f) = 1), the solution to the above equation will simply be the Inverse Discrete Fourier Transform of D(f), truncated to the desired number of coefficients. The user may specify the desired response and weighting function in one of two modes: band and points. In "band mode" the program assumes that the desired response and the weighting function are constant throughout a set of adjacent frequency bands from zero to half the sampling frequency. Bands are specified by parameters in a parameter file. In "points mode" the program allows the desired response and weighting function to be arbitrarily shaped and to be specified at a number of uniformly spaced points from zero to half the sampling frequency. The number of points must be one plus a power of two. The point values of the desired response and the weighting function are specified in two ASCII files. The first number in each of these files is an integer telling how many point values are in the file, and the point values follow. Among ESPS FIR design programs, this is the fastest and the most numerically stable program. However, due to the Gibbs phenomenon, overshoot in the passband near the transition bandedges exists.2 .2 .1 . Band Mode Example To illustrate the "band mode" of operation, a simple bandpass filter will be designed. The following command reads design parameters from a parameter file. wmse_filt -P param1.wmse band_pass1.filtThe parameter file is shown below. In this example, it creates a bandpass filter with passband edges at 1000 and 2000 Hz.Content of the parameter file param1.wmse: float samp_freq = 8000: "Sampling frequency:"; int filt_length = 201: "filter length - odd:"; int nbands = 3: "Number of bands:"; float band_edge1 = 0; float band_edge2 = 1000; float band_edge3 = 2000; float band_edge4 = 4000; float band1_des = 0: "desired value for band1:"; float band2_des = 1 "desired value for band2:"; float band3_des = 0 "desired value for band3:"; #uniform weighting float band1_wt = 1: "weighting value for band1:"; float band2_wt = 1: "weighting value for band2:"; float band3_wt = 1: "weighting value for band3:";The response for this filter is shown in Figure 2-2. Incidentally, it may be easier to use eparam or xeparam(1-ESPS) with wmse_filt(1-ESPS) to prompt for design parameters. By default, the parameter file $ESPS_BASE/lib/params/Pwmse_filt contains design parameters for a 3-band filter. You may use this as a template and construct a parameter file for designing a N-band filter. See next example for constructing a 5-band filter. You can obtain better stop band rejection by allowing the filter response to rolloff more slowly than in the above example. This can be accomplished with wmse_filt by specifying transition bands on either side of the passband, where the error is weighted with a factor of zero. This allows the filter design algorithm to concentrate the zeroes in the regions of interest since the error in the transition region can grow arbitrarily large without affecting the total weighted error. Note that the desired response function is the same in this example as in the one above, even though it is specified by using more bands. wmse_filt -P param2.wmse band_pass1.filtThe parameter file is shown below. In this example, it creates a bandpass filter with passband edges at 1000 and 2000 Hz, a 100 Hz transition region is provided on either side of the passband with zero error weighting.Content of the parameter file param2.wmse: float samp_freq = 8000: "Sampling frequency:"; int filt_length = 201: "filter length - odd:"; int nbands = 5: "Number of bands:"; float band_edge1 = 0; float band_edge2 = 900; float band_edge3 = 1000; float band_edge4 = 2000; float band_edge5 = 2100; float band_edge6 = 4000; float band1_des = 0: "desired value for band1:"; float band2_des = 0 "desired value for band2:"; float band3_des = 1 "desired value for band3:"; float band4_des = 0 "desired value for band4:"; float band5_des = 0 "desired value for band5:"; float band1_wt = 1: "weighting value for band1:"; float band2_wt = 0: "weighting value for band2:"; float band3_wt = 1: "weighting value for band3:"; float band4_wt = 0: "weighting value for band4"; float band5_wt = 1: "weighting value for band5:"; The response for this filter is shown in Figure 2-3. Note that the passband ripple has been reduced and the stop band attenuation has been increased by about 30 dB.2 .2 .2 . Points Mode Example. In this section, a more complicated filter will be designed using the "points mode" method. Suppose a filter with the amplitude response described as follows: over 0 to 8200 Hz, the amplitude response is proportional to frequency with a slope of +(1/820); over 8201 to 9200 Hz, with the slope of -(1/100); over 9201 to 10000Hz, the amplitude response is zero. And suppose the error weight over 0 to 8200 Hz is 1; over 8201 to 9200 Hz, 0; over 9201 to 10000 Hz, 1. This is a differentiator and could be used as an FM demodulation filter. Before the filter can be designed, ASCII files must be created containing the desired response and the weighting function. For best results, the number of points in these functions should be large. These ASCII files can be created easily by using a simple awk (1) command ( or Masscomp utilities gas (1G) and af (1G). ). cat > fm_des (This puts the number of points at the beginning of the file.) 1025 ^d awk '{x=0;print x;for(i=1;i<820;i++) print x+=0.012195121}' - >> fm_des <ret> ^d awk '{x=10;print x;for(i=1;i<100;i++) print x+=-0.1}' - >> fm_des <ret> ^d awk '{for(i=0;i<105;i++) print x=0}' - >>fm_des <ret> ^d The weighting function is created below. The transition band receives low weighting to improve performance in the pass band and stop band. cat > fm_wt 1025 ^d awk '{for(i=0;i<820;i++) print x=1}' - >> fm_wt <ret> ^d awk '{for(i=0;i<820;i++) print x=0.1}' - >> fm_wt <ret> ^d awk '{for(i=0;i<820;i++) print x=1}' - >> fm_wt <ret> ^dThe filter is designed with the following command: wmse_filt -c "FM demodulator." -n 401 -d fm_des -w fm_wt fm_demod.filtThe comment string following the -c option will be copied into the comment portion of the output file header. The response for this filter is shown on a linear scale in Figure 2-6.2 .3 . win_filt The program win_filt(1-ESPS) allows you to design a FIR filter by the Kasier windowing method. This method windows the ideal frequency response with the Kaiser window which controls the sharpness of the design filter. Windowing technique in FIR design often requires long filter length to meet the requirement of a sharp filter. The ideal frequency response of the filter is described by the parameters in a parameter files. To illustrate its usage, suppose a highpass filter with the cutoff frequency at 1500 Hz, sampled at 8000 Hz. Since the parameter template in $ESPS_BASE/lib/params is in a form of 2-band filter, we'll use eparam(1-ESPS) to invoke win_filt. eparam win_filt high.filt Sampling frequency: [8000] : Number of bands: [2] : ransition bandwidth: [100] : rejection in dB from one band to another: [20] : band_edge1 [0] : band_edge2 [1000] :1500 band_edge3 [4000] : desired value for band1: [1] :0 desired value for band2: [0] :1We required the transition bandwidth of 100 Hz and stopband response to be at least 20 dB down from passband. The filter response is shown below in Figure 2.52 .4 . pkmc_filt The design method is based on the Parks-McClellan algorithm. The resulting filter minimizes the maximum weighted approximation error. In other words, for desired response D(f) and error weighting function W(f), the program finds the coefficients of the filter H(f) which minimizes:One of the four standard FIR types is produced. For a filter with multiple stopbands and passbands, the Type 1 (symmetric and odd length) or Type 2 (symmetric and even length) filter is designed. For a differentiator or a Hilbert Transformer, the Type 3 (anti-symmetric and odd length) or the Type 4 (anti-symmetric and even length) filter is designed. The Parks-McClellan algorithm is known to run to numerically difficulty, especially if the filter length is over 100. However, since the algorithm can distribute error equally among passband and stopband by equirippling to avoid excessive overshoot near transition bandedges, filter designed by this method is preferred for certain application. Suppose a differentiator in Section 2.2.2 - over the 0 to 8200 Hz region, the amplitude response is proportional to frequency with a slope of +(1/820); over 8201 to 9200 Hz, with the slope of -(1/100); over 9201 to 10000Hz, the amplitude response is zero. And suppose the error weight over 0 to 8200 Hz is 1; over 8201 to 9200 Hz, 0; over 9201 to 10000 Hz, 1. A parameter file, param.diff based on the template, $ESPS_BASE/lib/params/Ppkmc_filt, follows:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?