MATLAB Examples

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 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 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 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 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

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 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 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.

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

Design a filter.

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

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.

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 math attributes in MATLAB® code.

Set fixed-point data types by instrumenting MATLAB® code for min/max logging and using the tools to propose data types.

Model, prototype, tune, and deploy algorithms using Simulink® and Embedded Coder® with the STM32F4 Discovery board. The audio filter tuning example demonstrates this workflow.

This demo shows how a fixed-point cordic algorithm to calculate a phase from polar coordinates (arctan) can be implemented in MATLAB.

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.

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.

Check, generate and verify HDL code from MATLAB® code that instantiates a non-restoring square root system object.

Generate HDL code from a MATLAB® design that implements a high dynamic range imaging algorithm.

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

HDL code generation from a fixed-point MATLAB® design that is ready for code generation.

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.

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

The recommended workflow for generating C code from a MATLAB function using the 'codegen' command. These are the steps: 1. Add the %#codegen directive to the MATLAB function to indicate that

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

Generate a standalone C library from MATLAB code that reads a file from disk using the standard C functions fopen/fread/fclose. To call these C functions, the MATLAB code uses the

Generate a MEX function from a simple MATLAB function using the 'codegen' command. You can use 'codegen' to check that your MATLAB code is suitable for code generation and, in many cases, to

Generate a MEX function and C source code from MATLAB code that performs portfolio optimization using the Black Litterman approach.

These examples are using Einstein's General Relativity to calculate geodesics in curved space-time.

Use code replacement libraries to replace operators and functions in the generated code. The MATLAB code described illustrates the replacement capabilities. With each example MATLAB

Accelerate the execution of a MATLAB algorithm that uses MATLAB classes. The classes create a reverberation effect, that is, the "echo" you hear in a large empty room.

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

Generate a standalone C library from MATLAB code that applies a simple histogram equalization function to images to improve image contrast. The example uses parfor to process each of the

Generate code for a MATLAB algorithm that runs a simulation of bouncing "atoms" and returns the result after a number of iterations. There are no upper bounds on the number of atoms that the

Generate a MEX function from a MATLAB function, 'compute_average', that uses persistent variables. It illustrates that you must clear the state of persistent variables before using 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

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

This example was authored by the MathWorks community.

Pack and unpack data using the provided packData and unpackData functions

This example shows how to generate code from packData and unpackData

Develop and use code replacement library entries for target-specific function implementations that require data to be aligned to optimize application performance. To configure data

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.

Choose your country 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 location 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.