MathWorks - Mobile View
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
MathWorks
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out

Videos and Webinars

  • MathWorks
  • Videos
  • Videos Home
  • Search
  • Videos Home
  • Search
  • Contact sales
  • Trial software
  Register to watch video
  • Description
  • Full Transcript
  • Related Resources

FPGA Design with MATLAB, Part 2: Modeling Hardware in Simulink

From the series: FPGA Design with MATLAB

Raghu Sivakumar, MathWorks

Efficiently targeting an algorithm to FPGA or ASIC hardware requires adaptations to handle streaming data and to optimize the amount of fixed resources required. Simulink® helps visualize the hardware architecture and data flow. If your original algorithm was developed in MATLAB®, you can reuse much of that work as you use Simulink to adapt the algorithm for hardware implementation.

This video covers:

  • Sharing workspace variables between MATLAB and Simulink
  • Using hardware design experience to adapt the algorithm for efficient implementation
  • Logging signals as test points for debugging
  • Visualizing data types and how they propagate through the design
  • Re-using the MATLAB code in a streaming MATLAB function block
  • Using the MATLAB testbench to simulate and verify the output of the Simulink hardware implementation

Welcome to the HDL Coder Video Series. In this video series we will learn a popular production proven path to take a MATLAB digital signal-processing algorithm through Simulink, Fixed-Point Designer, and HDL Coder to target an FPGA.

In the first part of the video series we discussed the strength of MATLAB and Simulink and provided an overview of the HDL Coder Self-Guided Tutorial available on the MathWorks File Exchange website. 

In this part of the video series we will pay attention on implementing the Simulink model for the Pulse Detection Algorithm and compare it with the golden reference.

Before we create the Simulink model, run the pulse_detector_reference algorithm. This will initialize all the parameters in the MATLAB workspace, which we will pull into the Simulink model during the build.

To stream the data in the Simulink model, we will use the “Signal from Workspace” block which will stream the Receive Signal one sample at a time. The sampled data is passed through the discrete FIR Filter block with its coefficients referencing the CorrFilter variable. Enable logging of specific signals during the build stages of the Simulink model. We will utilize the logged signals to verify the output of the Simulink model with the golden reference algorithm.

To implement the hardware-friendly peak detector, use the raw sum of the square of the real and complex magnitudes since using complex operations such as square root will end up being resource expensive. To evaluate the magnitude squared, the signal is split into its real and imaginary components with the following blocks: Enable the signal Dimensions and Port Data, to visualize the data changes in Simulink.

To detect the peak, the Tapped delay block buffers the magnitude squared signal into 11 samples to create the sliding window

To implement the above peak detection, we will copy the “Hardware Friendly” algorithm in the Simulink model using the MATLAB Function Block.

Copy and paste the algorithm in the MATLAB function block. We will modify the algorithm to work with the buffered sample data and define the WindowLen Variable as a parameter.

This method enables to detect the pulse immediately, as this processes the data sample that follows the pulse as they arrive. In addition, this technique avoids storing the entire data sample in a fixed RAM. The parameter argument in the MATLAB function block takes the value from the MATLAB model workspace.

Clear the tunable option, WindowLen must be a constant expression for code generation purpose.

The middle sample in the stored 11 samples is compared to the other 10 to see if it’s the largest of the 11, and if so, if it’s larger than the threshold we specify. The threshold is the key for identifying the peak versus all the local ones as we slide the window. 

The output of the peak detection implementation, signals “MidSample”
 and “detected” are inputs to a unit delay enabled block, which will hold the peak value for display when the detected signal is TRUE. To visualize the outcome, connect a ‘Display’ block.

Using the test bench script ‘pulse_detector_v1’, we will run the output comparison of the MATLAB golden reference and the Simulink hardware implementation model. The comparison proves that the Simulink streaming model matches with the MATLAB reference, and the error is just the floating-point precision error.

In the second part of this video series on the HDL Coder, we have implemented the hardware implementation in Simulink and compared it against the MATLAB golden reference. We have also demonstrated the seamless interaction between MATLAB and Simulink environments during the Simulink model build.

In the next video we will prepare the Simulink model for HDL code generation.

Related Products

  • HDL Coder

Learn More

Get HDL Coder Self-Guided Tutorial
Related Information
Request HDL Coder Trial

Feedback

Featured Product

HDL Coder

  • Request Trial
  • Get Pricing

Up Next:

Learn how to balance speed and area optimization of hardware micro-architecture for RTL generation.
4:48
Part 3: Architecting Efficient Hardware
View full series (5 Videos)

Related Videos:

23:30
Rapid Prototyping of Unknown Solutions to Only Partially...
20:02
A Guided Workflow for Zynq Using MATLAB and Simulink
30:14
Rapid Deployment of MATLAB and Simulink Designs on Xilinx...
2:01
Course Preview: Programming Xilinx Zynq SoCs with MATLAB...
19:50
How to Build Custom Motor Controllers for Zynq SoCs with...

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web site

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Contact sales
  • Trial software

Explore Products

  • MATLAB
  • Simulink
  • Student Software
  • Hardware Support
  • File Exchange

Try or Buy

  • Downloads
  • Trial Software
  • Contact Sales
  • Pricing and Licensing
  • How to Buy

Learn to Use

  • Documentation
  • Tutorials
  • Examples
  • Videos and Webinars
  • Training

Get Support

  • Installation Help
  • Answers
  • Consulting
  • License Center
  • Contact Support

About MathWorks

  • Careers
  • Newsroom
  • Social Mission
  • Contact Sales
  • About MathWorks

MathWorks

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Discover…

  • Select a Web Site United States
  • Patents
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Application Status

© 1994-2021 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Join the conversation

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic.  By continuing to use this website, you consent to our use of cookies.  Please see our Privacy Policy to learn more about cookies and how to change your settings.