filter.ascii
来自「speech signal process tools」· ASCII 代码 · 共 1,263 行 · 第 1/2 页
ASCII
1,263 行
string filt_type = "DIFFERENTIATOR": "Desired FIR kind:": {"MULTIBAND",\ "DIFFERENTIATOR", "HILBERT"}; int filt_length = 55: "Filter length:"; float samp_freq = 20000: "Sampling frequency:"; int nbands = 2: "Number of bands:"; float band1_edge1 = 0: "Left bandedge for band 1:"; float band1_edge2 = 8200: "Right bandedge for band 1:"; #slope is measured against normalized frequency axis float band1_des = 24.390244: "Value for band 1, or slope for differentiator"; float band1_wt = 1: "Weight for band 1"; float band2_edge1 = 9200: "Left bandedge for band 2:"; float band2_edge2 = 10000: "Right bandedge for band 2:"; float band2_des = 0: "Value for band 2"; float band2_wt = 1: "Weight for band2";The command, pkmc_filt -Pparam.diff fm_demod2.filtgives the FIR filter with the response shown in figure 2-62 .5 . cb_filt The program designs a FIR filter by applying the Simplex algorithm to solve a constraint-based problem. This is a public domain program with ESPS interface added. (See its man page for the source.) The main feature of this program is to design a FIR filter with a nearly flat passband. However, due to its generality, it requires high computational time and sometimes runs into numerical ill condition. If no feasible solution is found, relax constraints accordingly or consider other FIR design alternatives. Suppose a lowpass filter of sampling rate 8000 Hz, with passband from 0 to 1800 Hz, stopband from 2000 to 4000. It is desired that passband be nearly as flat as possible and filter length be between 91 and 55 taps. Please see the man page for parameter usage details. Brief comments are included in the following parameter file for our design example. #largest and smallest filter length int filt_length_L = 91; int filt_length_S = 55; float samp_freq = 8000; #number of specs int nspec = 5; string model = "cosine"; string push_direction = "neither"; #Upper bound and bandedge specs for passband string spec1_type = "limit"; string spec1_sense = "+"; float spec1_edge1 = 0.000000; float spec1_edge2 = 1800; float spec1_bound1 = 1.000000; float spec1_bound2 = 1.000000; string spec1_hug = "hugged"; string spec1_interp = "arithmetic"; #Lower bound and bandedge specs for passband string spec2_type = "limit"; string spec2_sense = "-"; float spec2_edge1 = 0.000000; float spec2_edge2 = 1800; float spec2_bound1 = 0.90000; float spec2_bound2 = 0.90000; string spec2_hug = "not hugged"; string spec2_interp = "arithmetic"; #Upper bound and bandedge specs for stopband string spec3_type = "limit"; string spec3_sense = "+"; float spec3_edge1 = 2000; float spec3_edge2 = 4000; float spec3_bound1 = 0.100000; float spec3_bound2 = 0.100000; string spec3_hug = "not hugged"; string spec3_interp = "arithmetic"; #Lower bound and bandedge specs for stopband string spec4_type = "limit"; string spec4_sense = "-"; float spec4_edge1 = 2000; float spec4_edge2 = 4000; float spec4_bound1 = 0; float spec4_bound2 = 0; string spec4_hug = "hugged"; string spec4_interp = "arithmetic"; #Near flatness constraint spec on passband string spec5_type = "concave"; string spec5_sense = "-"; float spec5_edge1 = 0; float spec5_edge2 = 1800;The command, cb_filt -P param.cb lowpass.cbproduces a filter with the spectral plot shown in figure 2.7.2 .6 . iir_filt The program iir_filt (1-ESPS) designs digital IIR filters by first designing Butterworth, Chebyshev I, Chebyshev II, or elliptical analog filters and then converting them to digital filters by using the bilinear transformation. Iir_filt supports the design of low pass (LP), high pass (HP), bandpass (BP), and band stop (BS) filters. The user must specify the sampling frequency, the filter type (e.g. Butterworth), filter response type (e.g. low pass), pass/stopband edges, passband deviation tolerance, and stopband attenuation characteristic. These design parameters are specified in a parameter file, but the easiest way to design IIR filters is by invoking iir_filt with the eparam or xeparam(1-ESPS) command. By doing this, the user is prompted for all the design parameters. Suppose a bandpass filter of 8000 Hz sampling rate. Its desired passband amplitude is equal to 1 and with maximum deviation of 1 dB over the region of 1000 to 2000 Hz. The stopband regions over 0 to 900 Hz and 2100 to 4000 Hz are required to have at least 30 dB attenuation from the passband.The following command designs such filter. eparam iir_filt iir.filt Desired filter type: [ELLIPTICAL] (Choices are: BUTTERWORTH CHEBYSHEV1 CHEBYSHEV2 ELLIPTICAL): Desired filter reponse [LP] (Choices are: LP HP BP BS):BP Desired sampling frequency. [8000] : Stopband frequency 1 [1100] :900 Passband frequency 1 [1000] : Passband frequency 2 [2100] :2000 Stopband frequency 2 [2000] :2100 Desired maximum pass band loss (dB). [1] : Desired minimum stop band attenuation (dB). [20] :30 Desired pass band gain. [1] :The response is in figure 2-8.2 .7 . xpz The program xpz (1-ESPS) designs filters by allowing the user to arbitrarily place poles and zeros. The pole and zero locations can be specified by interactively placing poles and zeros on the complex Z-plane by using the mouse, or by using a text editor window to specify their real and imaginary parts. Changes in filter characteristics are immediately displayed in the filter response window. See the manual page for more information.2 .8 . zero-pole The program zero_pole(1-ESPS) allows the user to design a filter by arbitrary placement of poles and zeros in the complex plane. The user simply specifies the pole and zero locations in one or two ASCII files, and the program computes the coefficients and deposits them in a FEAFILT (5-ESPS) file. The zero_pole program will be demonstrated by converting an analog Butterworth filter to its discrete equivalent by using the bilinear transformation. [1] The analog filter is a sixth-order low-pass filter with a 3-dB corner frequency at one eighth the sampling rate. After the transformation, in the Z-domain this filter has six zeroes at -1, and poles at the following locations: p0 = 0.597716978 + 0.577350268 i p5 = p0 conjugate. p1 = 0.471404518 + 0.333333333 i p4 = p1 conjugate. p2 = 0.420143458 + 0.108741129 i p3 = p2 conjugate.The filter is then designed with the following command: zero_pole -c "Sixth order Butterworth." -g 1 butter6.filt butter6 butter6 The -g option is used above to insure that the filter coefficients are normalized to have unity gain at 0 Hz. The ASCII file butter6 is shown below. Note that if zero and pole locations are both to be read out of the same file, it must be given twice on the command line. Also, for any pole or zero off of the real axis, the complex conjugate is automatically included and therefore should not be listed in the input ASCII file.Contents of butter6: 6 -1.0 0.0 -1.0 0.0 -1.0 0.0 -1.0 0.0 -1.0 0.0 -1.0 0.0 3 0.597716978 0.577350268 0.471404518 0.333333333 0.420143458 0.1087411292 .9 . impulse_resp The program impulse_resp (1-ESPS) is used to calculate the impulse response of a filter. A specified number of points on the impulse response are calculated and written either to an output FEAFILT (5-ESPS) file, to be used as an FIR filter, or to an FEA_SD (sampled data) file for plotting in the time domain. As an example, the bandpass IIR filter designed in the Section 2.7, iir.filt, will be converted to an FIR filter using impulse_resp. impulse_resp -n 100 iir.filt fir.filt The response for this filter is shown in Figure 2-9. If the user wishes to plot the impulse response in the time domain, the following command should be used to obtain a sampled-data FEA_SD file: impulse_resp -s -n 100 iir.filt iir.sdThis file is plotted in Figure 2-9 using plotsd (1-ESPS).2 .10 . atofilt The program atofilt (1-ESPS) is used to convert a set of known filter coefficients into a FEAFILT (5-ESPS) file. The coefficients may be placed in one or two ASCII files, or may be typed in directly from the standard input. The user is strongly advised to use the comment facility of this program to record information about the coefficients in the file header.An example command line would be: atofilt filter1.filt filter1.num filter1.denSince the -c option is not used above, the user will be prompted for his comments.3 . FILTERING PROGRAMS This section describes the three programs that may be used to filter sampled data: filter2 (1-ESPS), fft_filter (1-ESPS), and sfconvert (1-ESPS). Fft_filter (1-ESPS) works with FIR filters only, but filter2 (1-ESPS) works with both IIR and FIR filters. 3 .1 . filter2 The program filter2 (1-ESPS) is used to perform a digital filtering operation on sampled data. The program implements FIR or IIR filters and may read its coefficients from a FEAFILT (5-ESPS) file, or from a parameter file. If lowpass.filt is a FEAFILT filter file and speech.sd is a FEA_SD file, then, the command, filter2 -F lowpass.filt speech.sd speech.outoutput the file speech.out which is the filtered result. Instead of a FEAFILT file, It is possible to give filter coefficients to filter2(1-ESPS) in an ASCII form by means of parameter file. See the man page for details. The following command reads IIR filter coefficients from a parameter file and filters the data. Note that the filter must be named on the command line to extract the correct set of coefficients from the parameter file. filter2 -P params.filt -f low_pass speech.sd filt_speech.sdThe parameter file params.filt is shown below. In this example the filtering operation begins at the 10,000th point in the input file and processes 20,000 points. Contents of params.filt: # Don't do the whole file. int start = 10000 : "Starting point for analysis."; int nan = 20000 : "Number of points to process."; # Define the filter. from a lowpass elliptical filter of 1000 Hz passband frequency, # 1100 Hz stop band frequency, 1 dB max deviation over passband, 20 dB # down on stopband, sampling rate 8000 Hz. int low_pass_psiz = 2; int low_pass_zsiz = 2; float low_pass_zeros = { 0.11777, 0.99304, 0.62917, 0.7772} float low_pass_poles = { 0.63655, 0.36316, 0.67707, 0.68036} float low_pass_gain = 0.1019;3 .2 . fft_filter The program fft_filter (1-ESPS) implements FIR filtering operations on sampled data by performing the convolution in the frequency domain rather in the time domain as filter does. This algorithm is computationally more efficient than that used by filter2 when the number of filter coefficients is large. If N is the number of data points to process and N is the size of the filter, the regular filtering algorithm require on the order of N*N multiplications. By contrast, the algorithm used by fft_filt requires only about 2N logN +N multiplications. [1] In experimental results on a Masscomp 5610 s2st1m, filtering 100,000 samples, fft_filter required only one eighth as much time as filter2 to implement a 401 point filter and 25 % less time to implement a 51 point filter. In implementing an 11 point filter, however, fft_filter was only half as fast as filter2. The command below illustrates the use of fft_filter. Note that if the -F option is used to specify the filter coefficients and the -p option is used to specify the range of data points, no parameter file is necessary. The command below causes all of the data in the file to be processed. fft_filter -F low_pass.filt -p1: input.sd output.sd3 .3 . sfconvert This program does sampling frequency conversion for input sampled data file. By default, the program designs a lowpass interpolation/decimation filter using the Kaiser windowing method. A trade-off between the computational time and the output accuracy is balanced by specifying the filter transition bandwidth and stopband rejection ratio. The following example converts a CD-quality signal sampled at 44.1 KHz to a telephone-quality signal sampled at 8 KHz. The output signal is band-limited to 3.5 KHz, instead of the 4 KHz Nyquist rate, by specifying the corner frequency on the command line. sfconvert -s 8000 -c 3500 music44_1.sd music8.sd4 . FILTER SPECTRAL RESPONSES The program filtspec (1-ESPS) is used to find the frequency response of a filter. The program reads coefficients from a FEAFILT (5-ESPS) file and produces an output FEA_SPEC (5-ESPS) file. The program plotspec (1-ESPS) can then be used to plot the response on a terminal or printer. Suppose a FEA_FILT filter file iir.filt. To plot the response with y-axis in linear scale, the following command is used: filtspec -ml iir.filt iir.spec plotspec iir.specOr the following command may be used. filtspec -ml iir.filt - | plotspec - Filtspec(1-ESPS) writes the result to standard input which then is pipe to plotspec(1-ESPS) as standard input.5 . REFERENCES1. Steven A. Tretter, Descrete-Time Signal Processing, John Wiley & Sons (1976).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?