| Filter Design HDL Coder™ | ![]() |
| On this page… |
|---|
Generating Code for mfilt.farrowsrc Filters at the Command Line |
The coder supports code generation for multirate Farrow sample rate converters (mfilt.farrowsrc). mfilt.farrowsrc is a multirate filter structure that implements a sample rate converter with an arbitrary conversion factor determined by its interpolation and decimation factors.
Unlike a single-rate Farrow filter (see Generating Code for Single-Rate Farrow Filters), a multirate Farrow sample rate converter does not have a fractional delay input.
For general information on this filter structure, see the mfilt.farrowsrc reference page in the Filter Design Toolbox™ documentation.
You can generate HDL code for either a standalone mfilt.farrowsrc object , or a cascade that includes a mfilt.farrowsrc object . This secton provides simple examples for each case.
The following example instantiates a standalone fixed-point Farrow sample rate converter. The converter performs a conversion between two standard audio rates, from 44.1kHz to 48kHz. The example generates both VHDL code and a VHDL test bench.
[L,M] = rat(48/44.1); m = mfilt.farrowsrc(L,M); Hm.arithmetic = 'fixed'; ### Starting VHDL code generation process for filter: Hm ### Starting VHDL code generation process for filter: Hm ### Generating: C:\Work\hdlsrc\Hm.vhd ### Starting generation of Hm VHDL entity ### Starting generation of Hm VHDL architecture ### HDL latency is 2 samples ### Successful completion of VHDL code generation process for filter: Hm generatetb(Hm, 'TestBenchStimulus','noise'); ### Starting generation of VHDL Test Bench ### Generating input stimulus ### Done generating input stimulus; length 1344 samples. ### Generating: C:\Work\hdlsrc\Hm_tb.vhd ### Please wait ..... ### Done generating VHDL test bench.
The following example illustrates code generation for a cascade that include a mfilt.farrowsrc filter. The coder requires that the mfilt.farrowsrc filter is in the last position of the cascade.
Astop = 50; % Minimum stopband attenuation % First interpolate the original 8 kHz signal by 4 using a % cascade of FIR halfband filters. TW = .125; % Transition Width f2 = fdesign.interpolator(4,'Nyquist',4,'TW,Ast',TW,Astop); hfir = design(f2,'multistage','HalfbandDesignMethod','equiripple'); % Then, interpolate the intermediate 8x4=32 kHz signal by 44.1/32 = % 1.378125 to get the desired 44.1 kHz final sampling frequency. We use a % cubic Lagrange polynomial-based filter for this purpose. We first design % a single rate Farrow filter, then convert it to a multirate Farrow filter. N = 3; % Polynomial Order ffar = fdesign.fracdelay(0,'N',N); hfar = design(ffar,'lagrange'); [L,M]=rat(1.378125); % Interpolation and decimation factors hfar = mfilt.farrowsrc(L,M,hfar.Coefficients); % The overall filter is obtained by cascading the two filters. % For HDL code generation compatibility, the cascade of FIR filters is flattened. % Note that the mfilt.farrowsrc filter is at the end of the cascade. h2 = cascade(hfir.Stage(1), hfir.Stage(2),hfar);
FDATool and filterbuilder do not currently support mfilt.farrowsrc filters. If you want to generate code an mfilt.farrowsrc filter in the HDL code generation GUI , you can use the fdhdltool command, as in the following example:
[L,M] = rat(48/44.1); m = mfilt.farrowsrc(L,M); fdhdltool(m);
fdhdltool opens the Generate HDL dialog box for the mfilt.farrowsrc filter, as shown in the following figure.

As shown, the following code generation options are not supported for mfilt.farrowsrc filters and are disabled in the GUI:
Add pipeline registers
Distributed Arithmetic architecture
Fully or partially serial architectures
Multiple clock inputs
ModelSim .do file test bench generation
![]() | Generating Code for Polyphase Sample Rate Converters | Generating Code for Single-Rate Farrow Filters | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |