MATLAB Examples
Use the DSP System Toolbox™ and Fixed-Point Designer™ to design a three-stage, multirate, fixed-point filter that implements the filter chain of a Digital Down-Converter (DDC) designed
Illustrates how to generate HDL code for a Digital Up-Converter (DUC). A DUC is a digital circuit which converts a digital baseband signal to a passband signal. The input baseband signal is
Design and implement hardware efficient Sample Rate Converters for an arbitrary factor using polynomial-based (Farrow) structures. Sample Rate Conversion (SRC) between arbitrary
Illustrates how to generate HDL code for an ITU-R BT.601 luma filter with 8-bit input data and 10-bit output data. This filter is a low-pass filter with a -3 dB point of 3.2 MHz with a 13.5 MHz
Design a filter.
Illustrates how to generate HDL code for an FIR filter with a processor interface for loading coefficients. The filter can be programmed to any desired response by loading the coefficients
Illustrates how to generate HDL code for an inverse sinc (sin x/x) peaking filter that adds preemphasis to compensate for the inherent sinc response of the digital-to-analog converter
Illustrates how to generate HDL code for a fractional delay (Farrow) filter for timing recovery in a digital modem. A Farrow filter structure provides variable fractional delay for the
Illustrates how to generate HDL code for a 5th order Butterworth filter. The cutoff-frequency for this filter is very low relative to the sample rate, leading to a filter that is difficult to
Illustrates how to generate HDL code for a minimum phase FIRT filter with 10-bit input data. This is a bandpass filter with sample rate of 96 kHz and passband from approximately 19 kHz to 29 kHz.
Illustrates how to generate HDL code for a symmetrical FIR filter with fully parallel, fully serial, partly serial and cascade-serial architectures for a lowpass filter for an audio
Illustrates how to generate HDL code for bank of 24 first-order shelving filters that implement an audio tone control with 1 dB steps from -6 dB to +6 dB for bass and treble.
Illustrates how to generate HDL code for a lowpass FIR filter with Distributed Arithmetic (DA) architecture.
Compute square root using a CORDIC kernel algorithm in MATLAB®. CORDIC-based algorithms are critical to many embedded applications, including motor controls, navigation, signal
Use the CORDIC algorithm, polynomial approximation, and lookup table approaches to calculate the fixed-point, four quadrant inverse tangent. These implementations are approximations
Convert a textbook version of the Fast Fourier Transform (FFT) algorithm into fixed-point MATLAB® code.
Use both CORDIC-based and lookup table-based algorithms provided by the Fixed-Point Designer™ to approximate the MATLAB® sine (SIN) and cosine (COS) functions. Efficient fixed-point
This demo introduces user to the new and enhanced bitwise operators provided in Fixed Point toolbox in R2007b. These functions are supported by Embedded MATLAB block for both software and
Accelerate fixed-point algorithms using fiaccel function. You generate a MEX function from MATLAB® code, run the generated MEX function, and compare the execution speed with MATLAB code
Convert a finite impulse-response (FIR) filter to fixed point by separating the fixed-point type specification from the algorithm code.
Define unsigned and signed two's complement integer and fixed-point numbers.
This demo shows how a fixed-point cordic algorithm to calculate a phase from polar coordinates (arctan) can be implemented in MATLAB.
Write MATLAB® code that works for both floating-point and fixed-point data types. The algorithm used in this example is the QR factorization implemented via CORDIC (Coordinate Rotation
Develop and verify a simple fixed-point algorithm.
Compute sine and cosine using a CORDIC rotation kernel in MATLAB®. CORDIC-based algorithms are critical to many embedded applications, including motor controls, navigation, signal
Implement fixed-point square root using a lookup table. Lookup tables generate efficient code for embedded devices.
Convert Cartesian to polar coordinates using a CORDIC vectoring kernel algorithm in MATLAB®. CORDIC-based algorithms are critical to many embedded applications, including motor
Analyze a fixed-point state-space system to detect limit cycles.
Normalize data for use in lookup tables.
Perform basic fixed-point arithmetic operations.
Implement fixed-point log2 using a lookup table. Lookup tables generate efficient code for embedded devices.
The basics of how to use the fixed-point numeric object fi.
Compute and compare the statistics of the signal quantization error when using various rounding methods.
Perform binary point scaling in FI.
Set fixed-point data types by instrumenting MATLAB® code for min/max logging and using the tools to propose data types.
Set fixed point math attributes in MATLAB® code.
Demonstrates code generation with batch sizes greater than 1. This demo contains two examples, first, uses cnncodegen to generate code which takes in a batch of images as input. The second
Demonstrates code generation for a deep learning application using NVIDIA TensorRT™ library. It uses the codegen command to generate a MEX file to run prediction with a ResNet-50 image
Generate a MEX function from a MATLAB® function that computes the stereo disparity of two images.
Generate CUDA® MEX from MATLAB® code and perform feature matching between two images. This example uses the matchFeatures function from the Image Processing Toolbox™ to match the feature
Demonstrates how to use GPU Coder™ to leverage the CUDA® Fast Fourier Transform library (cuFFT) and compute two-dimensional FFT on a NVIDIA® GPU. The two-dimensional Fourier transform is
Object Recognition using Speeded-Up Robust Features (SURF) is composed of three steps - feature extraction, feature description, and feature matching. This example performs feature
Looks at how we can benchmark the solving of a linear system by generating GPU code. The MATLAB® code to solve for x in A*x = b is very simple. Most frequently, we use matrix left division, also
Demonstrates the use of image processing functions for GPU code generation. The example takes a foggy image as input and produces a defogged image. This is a typical implementation of fog
Generate CUDA® kernels for stencil type operations by implementing "Game of Life" by John H. Conway.
Generate CUDA® code from a simple MATLAB® function by using GPU Coder™. A Mandelbrot set implementation by using standard MATLAB commands acts as the entry-point function. This example
Integrate GPU Coder™ into Simulink®. While GPU Coder is not supported for Simulink blocks, you can still leverage GPUs in Simulink by generating a dynamic linked library (dll) using GPU
Integrate the CUDA® code generated for a deep learning network into Simulink®. While GPU Coder™ is not supported for Simulink blocks, you can still use the computational power of GPUs in
Deploy Image Processing Toolbox™ algorithms to a NVIDIA® Jetson TX1 board. The imtophat function that performs morphological top-hat filtering on a grayscale image is used as an example to
Generate HDL code from a MATLAB® design that does image enhancement using histogram equalization.
Use the HDL Coder™ to generate a custom HDL IP core which blinks LEDs on the Arrow® SoCKit® evaluation kit, and shows how to use Embedded Coder® to generate C code that runs on the ARM® processor
HDL code generation from a floating-point MATLAB® design that is not ready for code generation in two steps. First we use float2fixed conversion process to generate a lookup table based
Generate HDL code from a MATLAB® design that implements an LMS filter. It also shows how to design a testbench that implements noise cancellation using this filter.
Use MATLAB® HDL Workflow Advisor to generate a custom HDL IP core which blinks LEDs on FPGA board. The generated IP core can be used on Xilinx® Zynq® platform, or on any Xilinx FPGA with
Generate HDL code from a MATLAB® design implementing the adaptive median filter algorithm suited for HDL code generation.
Generate HDL code from MATLAB® design implementing an bisection algorithm to calculate the square root of a number in fixed point notation.
Use the HDL Coder™ to generate a custom HDL IP core which blinks LEDs on the Xilinx® Zynq® ZC702 evaluation kit, and shows how to use Embedded Coder® to generate C code that runs on the ARM®
Generate HDL code from a MATLAB® design implementing a RGB2YUV conversion.
Work with MATLAB® HDL Coder™ projects to generate HDL from MATLAB designs.
Perform a design-level area optimization in HDL Coder by converting constant multipliers into shifts and adds using canonical signed digit (CSD) techniques.
Generate modular HDL code from MATLAB® code containing functions.
Generate a MATLAB Function block from a MATLAB® design for system simulation, code generation, and FPGA programming in Simulink®.
Work with MATLAB® HDL Coder™ projects.
Generate HDL code from MATLAB® code modeling transfer data between transmit and receive FIFO.
Debug a Zynq design using HDL Coder™ and Embedded Coder® features.
Define and register a custom board and reference design in the HDL Coder™ SoC workflow. Using this example, you will be able to register the Digilent® Zybo Zynq™ development board and a custom
Generate HDL code from a MATLAB® design that adjusts image contrast by linearly scaling pixel values.
Start with a floating-point design in MATLAB, iteratively converge on an efficient fixed-point design in MATLAB, and verify the numerical accuracy of the generated fixed-point design.
Generate HDL code from a MATLAB® design that implements a high dynamic range imaging algorithm.
Check, generate and verify HDL code from MATLAB® code that instantiates a non-restoring square root system object.
MATLAB code generation from a floating-point MATLAB® design that is not ready for code generation. We use 'coder.approximate' function to generate a lookup table based MATLAB function.
HDL code generation from a fixed-point MATLAB® design that is ready for code generation.
This example shows how to generate code from packData and unpackData
Pack and unpack data using the provided packData and unpackData functions
Control whether structure arguments to generated entry-point functions are passed by reference or by value.
Generate code for a function that uses enumerated types. In this example, the enumerated types inherit from base type int32. The base type can be int8, uint8, int16, uint16, or int32.
Name the C structure type to use in code generated for a global structure.
Write a MATLAB function that uses structure arrays so that it is suitable for code generation. For code generation, you must first create a scalar template version of the structure before
Test the output of generated code by using MATLAB® unit tests with MATLAB® Coder™.
Test external C code by using MATLAB® unit tests with MATLAB® Coder™.
Pass data by reference to and from an external C function.
Use the ConstantInputs parameter to control whether a MEX function checks the value of a constant input argument.
Configure the build for external C/C++ code from within a MATLAB® function. Configure the build within a function so that you can more easily integrate it with other projects.
Integrate a simple C function with MATLAB® code by using coder.ceval. Consider the MATLAB function, mathOps:
Call a C function that uses data types that are not natively defined within MATLAB®.
Register and use a Microsoft® Visual C/C++ (MSVC) toolchain running on a 64-bit Windows® platform to compile a 32-bit dynamic link library (DLL). This example uses a Microsoft® compiler.
Generate a standalone C library from MATLAB code that implements a simple Sobel filter that performs edge detection on images. The example also shows how to generate and test a MEX function in
Generate a standalone C library from MATLAB code that reads a file from disk using the functions fopen/fread/fclose.
Register and use a toolchain to compile an executable. This example uses Intel® Compiler, but the concepts and API shown below can be used for any toolchain. The registered toolchain can be
Generate a MEX function and C source code from MATLAB code that performs portfolio optimization using the Black Litterman approach.
Generate C code for a MATLAB Kalman filter function, kalmanfilter , which estimates the position of a moving object based on past noisy measurements. It also shows how to generate a MEX
Integrate external code that operates on a C style array with MATLAB® code. The external code computes a summation over array data. You can customize the code to change the input data or
Use generated code to accelerate an application that you deploy with MATLAB® Compiler. The example accelerates an algorithm by using MATLAB® Coder™ to generate a MEX version of the
Accelerate MATLAB algorithm execution using a generated MEX function. It uses the codegen command to generate a MEX function for a complicated application that uses multiple MATLAB files.
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: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office