| |
Multirate filters provide a practical approach to designing and implementing finite response (FIR) filters with narrow spectral constraints. By changing the input data rate at one or more intermediate points the filter lengths and computational rates can be greatly reduced when compared to a standard single-rate filter implementation. In this technique, the sampling frequency is first decreased and the actual FIR filter is implemented at the lower sampling frequency which considerably reduces the complexity of the filter. Multirate filter designs can be easily modeled and analyzed using MATLAB and the Filter
Design Toolbox. Once an acceptable response has been designed the behavioral model
can be quickly converted into a synthesizable model and implemented on an FPGA using
AccelChip™ DSP Synthesis and AccelWare™ IP Cores. This design flow marries the Designing Multirate Filters Systems using Filter Design Toolbox The Filter Design Toolbox provides an easy method to design and analyze behavioral multirate filters models. It includes functions for designing: Polyphase interpolators Polyphase decimators Polyphase sample-rate converters CIC multirate filters and multistage-multirate filters. A list of the most common functions, referred to as the“mfilt” functions, is provided below:
The following example shows how two simple polyphase decimation filters can be created and analyzed using the “fvtool()” function. The first filter is a low-pass FIR filter.
The second filter, an equiripple FIR filter, is created in a similar manner.
We can analyze both filters simultaneously using the “fvtool” function from MATLAB. Figure 1 shows the magnitude for each filter superimposed onto a single plot. fvtool(h1,h2)
Figure 1 – fvtool plot of the polyphase filters The filter design toolbox provides an easy means to cascade multiple decimation filters into a multirate filter system as shown the Figure 2.
Figure 2 – Block Diagram of Cascaded Decimation FIR Filters
h3 = mfilt.cascade(h1,h2); The new magnitude response, which represents the combined effects of the two decimation filters is shown Figure 3.
Figure 3 – Plot of cascaded system of polyphase filters This simple example highlights the ease of use from which a multirate filter system can be modeled and refined using MATLAB. These concepts can be easily extended to include CIC filters and resampling data rates. Creating a Synthesizable MATLAB Model of a Multirate Filter System Converting a behavioral model of a multirate filter system into a synthesizable model is a 3 step process:
Replacing fvtool with User Defined Data In our previous example the filter analysis function “fvtool()” performs an ideal analysis
of the filter based on a predetermined set of filter input data such as an impulse or random
data. When targeting hardware a set of actual input test vectors will need to be generated
and processed through the filter. MATLAB provides a function called “filter()” that can
be used to run these user-defined input vectors through a filter object created using the The following example shows how analysis performed with the “fvtool” function can be substituted with analysis performed using a generated data set. The input data is generated using the “rand” function, filtered using the “filter” function and analyzed by plotting the power spectral density of the filtered output. % Create coefficients for a 21 tap low-pass FIR filter using "firceqrip" % Use the “cfir” coefficients to create a polyphase decimation by 2 filter % Create coefficients for a 63 tap lowpass filter using "firgr" % Use the “pfir” coefficients to create a polyphase decimation by 2 filter % Combine the two polyphase decimation filters into a multirate filter system % Analyze the combined filter response using "fvtool"
The plot below shows the magnitude response of the filtered data superimposed onto the
Figure 4 – Filtered data superimposed on ideal magnitude response Creating the Design Function Call and Streaming Loop The synthesizable MATLAB coding style dictates that code, to be implemented in hardware, is separated into a function called the “design function”. This function is then placed inside a loop called the “streaming loop”. Filters implemented on an FPGA or ASIC are generally implemented in a streaming fashion where the input samples are applied to the filter one at a time. This behavior needs to be defined in the streaming loop as shown in the example below. Decimation multirate systems are accomplished in AccelChip by running the hardware at the highest clock rate and selectively ignoring output samples. Likewise interpolation multirate systems are accomplished by again running the hardware at the highest clock frequency and selectively ignoring input samples. In the example below the streaming Note that the original use of the “filter” function is now being used to generate golden data that can be used as reference. This is a useful technique for monitoring the functionality and quantization error as we convert the synthesizable filter model to fixed-point. % Save the behavioral filter results for reference
Creating a Synthesizable Multirate Filter System Model When creating the design function simplest approach is to use synthesizable AccelWare™ MATLAB models for the decimation filters. AccelWare offers over 50 Parameterizable IP cores that are functionally equivalent replacements for MATLAB toolbox and built-in functions. The table below summarizes the AccelWare multirate filters and their functionally equivalent MATLAB counterpart.
In our previous example AccelWare “firdecim” functions will need to be generated for the “cfir” and “pfir” decimation by 2 filters.
Figure 5 – AccelWare Generation of Polyphase Decimation Filters Once generated these functions must then be instantiated into the design function. To simplify the process of modeling hardware a “valid” signal is provided, as part of the AccelWare decimation filter, to indicate when a valid “downsampled” output is available. The following MATLAB example shows now these models are instantiated.
By outputting the second valid signal “Fvalid2” from the design function we can simplify the capture of output samples in the top-level script file by adding some simple conditional control and an index counter to the streaming loop.
% Save the behavioral filter results for reference
% Calculate the power spectral density of the filter output If we simulate this model we see that the magnitude response if the synthesizable filter is similar. The AccelWare polyphase decimation filter modeled in fixed-point which is resulting in a small amount of quantization error.
Figure 6 – Synthesizable Filter Magnitude Response
The Filter Design Toolbox “mfilt” function provides a straightforward method for designing a multirate filter response. AccelChip provides functionally equivalent AccelWare IP cores that can be used to quickly create a version of the multirate filter system MATLAB model suitable for hardware. Adopting a MATLAB based hardware design flow is efficient, minimizes design environments and facilitates the use of the behavioral model as a golden reference. References [1] Ricardo A. Losada, “Practical FIR Filter Design in MATLAB”
Appendix A – Multirate Decimation Filter System Design Example Top-Level Script File % Create a 21 tap low-pass FIR filter using "firceqrip" %Decimate the filter by 2 % Create a 63 simple equiripple lowpass filter using "firgr" % Decimate the filter by 2 % Combine the two previous decimation filters in series using "cascade" % Analyze the filter response using "fvtool" % Generate the input samples using "rand". % Filter the input data index = 1; % Analyze the magnitude response of the results and add to fvtool plot Design Function function [Fout2,Fvalid2] = synth_multrate_filter(y) % Only clock in valid new data from firdecim_001 into firdecim_002 Appendix B – Digital Down Converter Example This second design example provides a MATLAB example of a three-stage decimator that is used in a digital down converter.
Figure 7 – 3-stage DDC Decimation Filter Behavioral MATLAB Model % Design CIC Decimation by 64 filter % Normalize the gain of the CIC filter % Design decimation by 2 polyphase filter % Design decimation by 2 polyphase filter % Cascade the 3 filters to create the multirate filter system % Plot the Response % Saving filter coefficients to a text file to use with AccelWare IP core Synthesizable MATLAB Top-Level Script File This model shows a design function “gsm_ddc” was created and instantiated in a streaming loop. Also shown is that an input data vector is created using random numbers, filtered and analyzed. The analysis function “aw_psd” will return the power spectral density. This file is provided by AccelChip. A similar function is available from The Mathworks called ‘dspdata.dsp”. NUM_OUTPUT_SAMPLES = 1024; %Set number of input sample to simulate % create random, uniformly distributed input for n = 1:(NUM_OUTPUT_SAMPLES*DecRate)
end % plot input power spectrum % plot output power spectrum Synthesizable MATLAB Design Function This synthesizable design function uses a CIC decimation filter and two polyphase decimation filters generated using the AccelWare IP core generator. Generating these filters required, as an input, the coefficients text files saved as part of the behavioral simulation function [data_out, pfir_Valid] = gsm_ddc(data_in) % Normalize the input data into the CIC % Perform the CIC Integration Filter % Normalize the CIC filter output to compensate for the gain % Second Stage % Third Stage % Mux the output for valid samples --------------------------------------------------------------------- by Tom Hill, Technical Marketing Manager, AccelChip, Inc.
September 15, 2005 Comments on this article? Send them to comments@fpgajournal.com |
||||||||
All
material on this site copyright © 2006 techfocus media, inc.
All rights reserved.
FPGA and Structured ASIC Journal Privacy Statement |