MATLAB Examples

Generate HDL From the Command Prompt

Design a filter.

d = fdesign.lowpass('Fp,Fst,Ap,Ast',0.2,0.22,1,60)
Hd = design(d,'equiripple','filterstructure','dfsymfir','Systemobject',true)
d = 

  lowpass with properties:

               Response: 'Lowpass'
          Specification: 'Fp,Fst,Ap,Ast'
            Description: {4x1 cell}
    NormalizedFrequency: 1
                  Fpass: 0.2000
                  Fstop: 0.2200
                  Apass: 1
                  Astop: 60


Hd = 

  dsp.FIRFilter with properties:

            Structure: 'Direct form symmetric'
      NumeratorSource: 'Property'
            Numerator: [1x202 double]
    InitialConditions: 0

  Use get to show all properties

To generate HDL code for the filter and its test bench from the command line, use the generatehdl function. When you call the generatehdl function, specify the filter name and (optionally) desired property name and property value pairs. When the filter is a System object™, you must specify the input data type property.

As code generation proceeds, a sequence of messages appears in the MATLAB Command Window. The messages include hyperlinks to the generated code and test bench files. Click these hyperlinks to open the code files in the MATLAB Editor.

generatehdl(Hd,'InputDataType',numerictype(1,16,15),'Name','MyFilter',...
               'TargetLanguage','Verilog','GenerateHDLTestbench', 'on')
### Starting Verilog code generation process for filter: MyFilter
### Generating: <a href="matlab:edit('/private/tmp/Bdoc17b_685977_71560/publish_examples2/tp9fba3d40/ex97122369/hdlsrc/MyFilter.v')">/private/tmp/Bdoc17b_685977_71560/publish_examples2/tp9fba3d40/ex97122369/hdlsrc/MyFilter.v</a>
### Starting generation of MyFilter Verilog module
### Starting generation of MyFilter Verilog module body
### Successful completion of Verilog code generation process for filter: MyFilter
### HDL latency is 2 samples
### Starting generation of VERILOG Test Bench.
### Generating input stimulus
### Done generating input stimulus; length 4486 samples.
### Generating Test bench: <a href="matlab:edit('/private/tmp/Bdoc17b_685977_71560/publish_examples2/tp9fba3d40/ex97122369/hdlsrc/MyFilter_tb.v')">/private/tmp/Bdoc17b_685977_71560/publish_examples2/tp9fba3d40/ex97122369/hdlsrc/MyFilter_tb.v</a>
### Creating stimulus vectors ...
### Done generating VERILOG Test Bench.