Documentation

Single-Rate Farrow Filters

About Code Generation for Single-Rate Farrow Filters

The coder supports HDL code generation for these single-rate Farrow filter structures:

  • dfilt.farrowlinearfd

  • dfilt.farrowfd

A Farrow filter differs from a conventional filter because it has a fractional delay input in addition to a signal input. The fractional delay input enables the use of time-varying delays, as the filter operates. The fractional delay input receives a signal taking on values from 0 through 1.0. For general information how to construct and use Farrow filter objects, see the DSP System Toolbox™ documentation.

The coder provides generatehdl properties and equivalent GUI options that let you:

  • Define the fractional delay port name used in generated code.

  • Apply various test bench stimulus signals to the fractional delay port, or define your own stimulus signal.

Code Generation Properties for Farrow Filters

The following properties support Farrow filter code generation:

  • FracDelayPort (string). This property specifies the name of the fractional delay port in generated code. The default name is 'filter_fd'. In the following example, the name 'FractionalDelay' is assigned to the fractional delay port.

    D = .3;
    hd = dfilt.farrowfd(D);
    generatehdl(hd,'FracDelayPort','FractionalDelay');
    
  • TestBenchFracDelayStimulus (string). This property specifies a stimulus signal applied to the fractional delay port in test bench code.

    By default, a constant value is obtained from the FracDelay property of the Farrow filter object, and applied to the fractional delay port. To use the default, leave the TestBenchFracDelayStimulus property unspecified, or pass in the empty string (''). In the following example, the FracDelay property is set to 0.6, and this value is used (by default) as the fractional delay stimulus.

    D = .3;
    hd = dfilt.farrowfd(D);
    hd.Fracdelay = 0.6;
    generatehdl(hd,'GenerateHDLTestbench','on');
    

    Alternatively, you can specify generation of the following types of stimulus vectors:

    • 'RandSweep': A vector of random values between 0 and 1. This stimulus signal has the same duration as the input to the filter, but changes at a slower rate. Each fractional delay value obtained from the vector is held for 10% of the total duration of the input signal.

    • 'RampSweep': A vector of values incrementally increasing over the range from 0 to 1. This stimulus signal has the same duration as the input to the filter, but changes at a slower rate. Each fractional delay value obtained from the vector is held for 10% of the total duration of the input signal.

    • A user-defined stimulus vector. You can pass in a call to a function that returns a vector. Alternatively, create the vector in the workspace and pass it in as shown in the following code example:

      D = .3;
      hd = dfilt.farrowfd(D);
      inputdata = generatetbstimulus(hd, 'TestBenchStimulus', {'ramp'});
      mytestv = [0.5*ones(1, length(inputdata)/2), 0.2*ones(1, length(inputdata)/2)];
      generatehdl(hd,'GenerateHDLTestbench','on','TestBenchStimulus',{'noise'},...
      'TestbenchFracDelayStimulus',mytestv);
      

        Note:   A user-defined fractional delay stimulus signal must have the same length as the test bench input signal. If the two signals do not have equal length, test bench generation terminates with an error message. The error message displays the signal lengths, as shown in the following example:

        D = .3;
        hd = dfilt.farrowfd(D);
        inputdata = generatetbstimulus(hd, 'TestBenchStimulus', {'ramp'});
        mytestv = [0.5*ones(1, length(inputdata)/2), 0.2*ones(1, length(inputdata)/2)];
        generatehdl(hd,'GenerateHDLTestbench','on','TestBenchStimulus',{'noise' 'chirp'},...
        'TestbenchFracDelayStimulus',mytestv)
        
        ??? Error using ==> generatevhdltb
        The lengths of specified vectors for FracDelay (1026) and Input (2052) do not match.

GUI Options for Farrow Filters

This section describes Farrow filter code generation options that are available in the Filter Design HDL Coder™ GUI. These options correspond to the properties described in Code Generation Properties for Farrow Filters.

    Note:   The Farrow filter options are displayed only when a Farrow filter is selected for HDL code generation.

The Farrow filter options are:

  • The Fractional delay port field in the Ports pane of the Generate HDL dialog box (shown) specifies the name of the fractional delay port in generated code. The default name is filter_fd.

  • The Fractional delay stimulus pop-up list in the Test Bench pane of the Generate HDL dialog box (shown) lets you select a stimulus signal. This signal is applied to the fractional delay port in the generated test bench.

    The Fractional delay stimulus list lets you select generation of the following types of stimulus signals:

    • Get value from filter: (default). A constant value is obtained from the FracDelay property of the Farrow filter object, and applied to the fractional delay port.

    • Ramp sweep. A vector of values incrementally increasing over the range from 0 to 1. This stimulus signal has the same duration as the input to the filter, but changes at a slower rate. Each fractional delay value obtained from the vector is held for 10% of the total duration of the input signal.

    • Random sweep. A vector of random values between 0 and 1. This stimulus signal has the same duration as the input to the filter, but changes at a slower rate. Each fractional delay value obtained from the vector is held for 10% of the total duration of the input signal.

    • User defined. When you select this option, the User defined stimulus field is enabled. You can enter a call to a function that returns a vector in the User defined stimulus field. Alternatively, create the vector as a workspace variable and enter the variable name, as shown in the following figure.

Farrow Filter Code Generation Mechanics

FDATool does not support design or import of Farrow filters. To generate HDL code for a Farrow filter, use one of the following methods:

  • Use the MATLAB® command line to create a Farrow filter object, initiate code generation, and set Farrow-related properties, as in the examples shown in Code Generation Properties for Farrow Filters.

  • Use the MATLAB command line to create a Farrow filter object. Then open the Generate HDL dialog box. For example, these commands create a Farrow linear fractional delay filter object Hd and pass it in to fdhdltool:

    D = .3
    Hd = dfilt.farrowlinearfd(D)
    Hd.arithmetic = 'fixed'
    fdhdltool(Hd) 

  • Use filterbuilder to design a Farrow (fractional delay) filter object. Then, select the Code Generation pane of the filterbuilder dialog box (shown). To open the Generate HDL dialog box, click the Generate HDL button. Then you can specify code generation options, and generate code.

Options Disabled for Farrow Filters

The coder disables some options or sets them to fixed default value when the Generate HDL dialog box opens with a Farrow filter. The options affected are:

Architecture. The coder sets this option to its default (Fully parallel) and disables it.

Clock inputs. The coder sets this option to its default (Single) and disables it.

Was this topic helpful?