MATLAB Examples

Design lowpass filters. The example highlights some of the most commonly used command-line tools in the DSP System Toolbox. Alternatively, you can use the Filter Builder app to implement

Use System objects to do streaming signal processing in MATLAB. The signals are read in and processed frame by frame (or block by block) in each processing loop. You can control the size of each

Visualize and measure signals in the time and frequency domain in MATLAB using a time scope and spectrum analyzer.

Lowpass filter a noisy signal in MATLAB and visualize the original and filtered signals using a spectrum analyzer. For a Simulink version of this example, see Filter Frames of a Noisy Sine

Model an algorithm specification for a three band parametric equalizer which will be used for code generation.

Use the Streaming Testbench Generator app to generate DSP algorithm testbenches. The DSP algorithm generated in this example is similar to the algorithm in the Filter Frames of a Noisy Sine

Design filters for use with fixed-point input. The example analyzes the effect of coefficient quantization on filter design. You must have the Fixed-Point Designer software™ to run this

Demonstrates how to generate HDL code for a programmable FIR filter. You can program the filter to a desired response by loading the coefficients into internal registers using the host

To estimate the transfer function of a system in MATLAB, use the dsp.TransferFunctionEstimator System object. The object implements the Welch's average modified periodogram method and

Alternately, you can compute the power spectrum of the signal using the dsp.SpectrumEstimator System object. You can acquire the output of the spectrum estimator and store the data for

You can design and implement the FIR multirate filters in Simulink using the FIR Decimation, FIR Interpolation, and FIR Rate Conversion blocks. When you set Coefficient source to Dialog

Sample rate conversion is a process of converting the sample rate of a signal from one sampling rate to another sampling rate. Multistage filters minimize the amount of computation involved

To implement an FIR Decimator, you must first design it by using the designMultirateFIR function. Specify the decimation factor of interest (usually greater than 1) and an interpolation

Use the MATLAB Compiler™ to create a standalone application from a MATLAB function that uses System objects from DSP System Toolbox™.

To view the power spectrum of a signal, you can use the dsp.SpectrumAnalyzer System object™. You can change the dynamics of the input signal and see the effect those changes have on the power

Generate a standalone executable for streaming statistics using MATLAB Coder™ and tune the generated executable using a user interface (UI) that is running in MATLAB (TM).

Use the Least Mean Square (LMS) algorithm to subtract noise from an input signal. The LMS adaptive filter uses the reference signal on the Input port and the desired signal on the Desired port

Use an RLS filter to extract useful information from a noisy signal. The information bearing signal is a sine wave that is corrupted by additive white gaussian noise.

Apply adaptive filters to signal separation using a structure called an adaptive line enhancer (ALE). In adaptive line enhancement, a measured signal x(n) contains two signals, an unknown

Adaptively estimate the time delay for a noisy input signal using the LMS adaptive FIR algorithm. The peak in the filter taps vector indicates the time-delay estimate.

Use a recursive least-squares (RLS) filter to identify an unknown system modeled with a lowpass FIR filter. Transfer function estimation is used to compare the frequency response of the

Track the time-varying weights of a nonstationary channel using the Recursive Least Squares (RLS) algorithm.

Subtract noise from an input signal using the Recursive Least Squares (RLS) algorithm. The RLS adaptive filter uses the reference signal on the Input port and the desired signal on the

The convergence path taken by different adaptive filtering algorithms. The plot is a sequence of points of the form (w1,w2) where w1 and w2 are the weights of the adaptive filter. The blue dots

Use the Kalman filter in an application that involves estimating the position of an aircraft through a model for RADAR measurements. A user interface (UI) allows the user to control various

Apply adaptive filters to noise removal using adaptive noise canceling. The example uses a user interface (UI) which can be launched by typing the command

Use a Filtered-X LMS algorithm in Adaptive Noise Control (ANC).

Model a dual-tone multifrequency (DTMF) generator and receiver. The model includes a bandpass filter bank receiver, a spectrum analyzer block showing a spectrum and spectrogram plot of

Compare three different delta-modulation (DM) waveform quantization, or coding, techniques.

Implement two common methods of envelope detection. One method uses squaring and lowpass filtering. The other uses the Hilbert transform. This example illustrates MATLAB® and Simulink®

Use a Kalman filter to estimate an aircraft's position and velocity from noisy radar measurements.

Use the UDP Send and UDP Receive System objects to transmit audio data over a network.

SAR [1] is a technique for computing high-resolution radar returns that exceed the traditional resolution limits imposed by the physical size, or aperture, of an antenna. SAR exploits

Model an algorithm specification for a three band parametric equalizer

Use the digital up converter (DUC) and digital down converter (DDC) System objects to design a Family Radio Service (FRS) transmitter and receiver. These objects provide tools to design

Illustrates using the UDP Send and UDP Receive blocks to transmit audio data over a network.

Use the digital down converter (DDC) System object to emulate the TI Graychip 4016 digital down converter in a simple manner. We base the example on a comparison with the GSM Digital Down

An implementation of a digital receiver that synchronizes to the time code information broadcast by radio station WWV and decodes it to display time information. The example uses the

Design filters given customized magnitude and phase specifications. Custom magnitude and phase design specifications are used for the equalization of magnitude and phase distortions

Use complex multirate filters in the implementation of Digital Down-Converters (DDC). The DDC is a key component of digital radios. It performs the frequency translation necessary to

Implements the Internet Low Bitrate Codec (iLBC) and illustrates its use. iLBC is designed for encoding and decoding speech for transmission via VoIP (Voice Over Internet Protocol).

Single sideband (SSB) modulation using sample-based and frame-based processing.

Reconstruct three independent combined signals transmitted over a single communications link using a Wavelet Transmultiplexer (WTM). The example illustrates the perfect

Use a MIDI control surface as a physical user interface to a Simulink model, allowing you to use knobs, sliders and buttons to interact with that model. It can be used in Simulink as well as with

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

Implement the ITU-T G.729 Voice Activity Detector (VAD)

Detect the QRS complex of electrocardiogram (ECG) signal in real-time. Model based design is used to assist in the development, testing and deployment of the algorithm.

Use the dspunfold function to generate a multi-threaded MEX file from a MATLAB function.

Use dspunfold to accelerate the simulation of a polyphase synthesis FFT filter bank by generating a multi-threaded mex file. This example requires MATLAB Coder.

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

Design lowpass FIR filters. Many of the concepts presented here can be extended to other responses such as highpass, bandpass, etc.

Design arbitrary group delay filters using the fdesign.arbgrpdelay filter designer. This designer uses a least-Pth constrained optimization algorithm to design allpass IIR filters

Design FIR halfband filters. Halfband filters are widely used in multirate signal processing applications when interpolating/decimating by a factor of two. Halfband filters are

Design classic IIR filters. The initial focus is on the situation for which the critical design parameter is the cutoff frequency at which the filter's power decays to half (-3 dB) the nominal

Design lowpass FIR Nyquist filters. It also compares these filters with raised cosine and square root raised cosine filters. These filters are widely used in pulse-shaping for digital

Design complex bandpass filters. Complex bandpass filters are used in many applications from IF subsampling digital down converters to vestigial sideband modulation schemes for analog

Design digital fractional delay filters that are implemented using Farrow structures. Digital fractional delay (fracDelay) filters are useful tools to fine-tune the sampling instants

Design peaking and notching filters. Filters that peak or notch at a certain frequency are useful to retain or eliminate a particular frequency component of a signal. The design parameters

Design least Pth-norm FIR filters with the FIRLPNORM function. This function uses a least-Pth unconstrained optimization algorithm to design FIR filters with arbitrary magnitude

Design optimal IIR filters with arbitrary magnitude response using the least-Pth unconstrained optimization algorithm.

Design filters with arbitrary magnitude response. The family of filter design (FDESIGN) objects allow for the design of filters with various types of responses. Among these types, the

Use some of the key features of the generalized Remez FIR filter design function. This function provides all the functionality included in FIRPM plus many additional features showcased

Design efficient FIR filters with very narrow transition-bands using multistage techniques. The techniques can be extended to the design of multirate filters. See Multistage Design Of

Minimize the number coefficients, by designing minimum-phase or minimum-order filters.

Design lowpass filters with stopbands that are not equiripple.

Control the filter order, passband ripple, stopband attenuation, and transition region width of a lowpass FIR filter.

Design a lowpass FIR filter using fdesign. An ideal lowpass filter requires an infinite impulse response. Truncating or windowing the impulse response results in the so-called window

Lowpass filter an ECG signal that contains high frequency noise.

Design filters for decimation and interpolation. Typically lowpass filters are used for decimation and for interpolation. When decimating, lowpass filters are used to reduce the

Remove the high-frequency outliers from a streaming signal using the dsp.MedianFilter System object™.

The efficiency gains that are possible when using multirate and multistage filters for certain applications. In this case a distinct advantage is achieved over regular linear-phase

Synthesize a series of four stereo signals into a broadband signal by using the Channel Synthesizer block. At the receiving end of the model, split this broadband signal back into the

Implement a 25-tap lowpass FIR filter by using the docid:dsp_ref.bvi0_ng-1 block.

Implement a 32-tap lowpass FIR filter by using the docid:dsp_ref.bvi0_ng-1 block.

Simulate steady-state behavior of a fixed-point digital down converter for GSM (Global System for Mobile) baseband conversions. The example uses signal processing System objects to

Simulate the design of a cochlear implant that can be placed in the inner ear of a profoundly deaf person to restore partial hearing. Signal processing is used in cochlear implant development

Optimize fixed-point FIR filters. The optimization can refer to the characteristics of the filter response such as the stopband attenuation or the number of bits required to achieve a

The application envisioned for this example is automatic lane tracking on a road. We will show how to fit a polynomial to noisy data representing the lane boundary of the road ahead of a

Convert a floating-point system to fixed point using the Fixed-Point Advisor from Fixed-Point Designer™.

Use the Fixed-Point Converter App to convert an IIR filter from a floating-point to a fixed-point implementation. Second-order sections (also referred as biquadratic) structures work

Sample rate conversion of an audio signal from 22.050 kHz to 8 kHz using a multirate FIR rate conversion approach.

Efficiently convert sample rates between arbitrary factors.

Design IIR polyphase filters.

Design perfect reconstruction two-channel filter banks, also known as the Quadrature Mirror Filter (QMF) Banks since they use power complementary filters.

Design multistage decimators and interpolators. The example Efficient Narrow Transition-Band FIR Filter Design showed how to apply the IFIR and the MULTISTAGE approaches to single-rate

Note : If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x) .

Create a new model based on the dsp_basic_filter template, add a spectral mask to its Spectrum Analyzer block, and run the model.

Create a binary file with a custom header using the Binary File Writer block. Write data to this file. Read the header and data using the Binary File Reader block.

The Binary File Writer and Binary File Reader blocks do not support writing and reading characters. As a workaround, cast character data to one of the built-in data types and write the integer

By default, the Binary File Reader block uses the endianness of the host machine. To change the endianness, such as when the host machine that writes the data does not have the same endianness

Use a Binary File Reader block to read real and complex matrix data from a binary file in a row-major format.

Visualize frequency input signals with the Spectrum Analyzer block.

The Binary File Writer and Binary File Reader blocks do not support writing and reading fixed-point data. As a workaround, you can write the stored integer portion of the fi data, read the

Delay the input signal using the Variable Fractional Delay block. Each delay value is unique and can vary from sample to sample within a frame, and can vary across channels. You can compute

Measure performance characteristics of a pulse width modulated sinusoid. The example contains a model which you can modify to view the effects of parameter changes on rise time, fall time,

Perform measurements using the Spectrum Analyzer block. The example contains a typical setup to perform harmonic distortion measurements (THD, SNR, SINAD, SFDR), third-order

Create a dsp.MovingAverage System object™ to compute the 10-point moving average of the streaming signal. Use a dsp.MatFileReader System object to read data from the accelerometer MAT

Compare the frequency response of the moving average filter with that of the regular FIR filter. Set the coefficients of the regular FIR filter as a sequence of scaled 1's. The scaling factor

Compute the energy of a signal from the signal's RMS value and compares the energy value with a specified threshold. Detect the event when the signal energy is above the threshold.

Compute the moving average of a signal using the movmean function.

Measures the pulse and transition metrics of a noisy rectangular pulse. Pulse metrics include rise time, fall time, pulse width, and pulse period. Transition metrics include middle-cross

The bin boundaries created by the Histogram block are determined by the data type of the input. The following two models show the differences in the output of the Histogram block based on the

Compute the running mean of a 3-by-2 matrix input, dsp_examples_u, using the Mean block.

Compute the running minimum of a 3-by-2 matrix input, dsp_examples_u, using the Minimum block.

Compute the maximum of a 3-by-2 matrix input, dsp_examples_u, using the Maximum block.

Compute the running maximum of a 3-by-2 matrix input, dsp_examples_u, using the Maximum block.

Compute the mean of a 3-by-2 matrix input, dsp_examples_u, using the Mean block.

Compute the minimum of a 3-by-2 matrix input, dsp_examples_u, using the Minimum block.

Implement a speech compression technique known as Linear Prediction Coding (LPC) using DSP System Toolbox™ functionality available at the MATLAB® command line.

Takes the perspective of a MATLAB developer willing to author an instantaneous frequency estimator based on a Discrete Energy Separation Algorithm. It also introduces creating System

Perform statistical measurements on an input data stream using DSP System Toolbox™ functionality available at the MATLAB® command line. You will compute the signal statistics minimum,

Use the DyadicAnalysis and DyadicSynthesis System objects to remove noise from a signal.

Create and use two different System objects to facilitate the streaming of data in and out of MATLAB: dspdemo.TextFileReader and dspdemo.TextFileWriter.

The Vector Quantizer Design process using Generalized Lloyd Algorithm (GLA) for a two dimensional input.

Use the DSP Testbench Generator Example App in order to quickly generate DSP Algorithm testbenches which accelerate the development and testing of streaming signal processing

Perform high resolution spectral analysis by using an efficient filter bank sometimes referred to as a channelizer. For comparison purposes, a traditional averaged modified periodogram

Explores different outlier removal filters and uses an electrocardiogram (ECG) signal as input.

Showcases zoom FFT, which is a signal processing technique used to analyze a portion of a spectrum at high resolution. DSP System Toolbox offers this functionality in MATLAB through the

The Zoom FFT block implements zoom FFT based on the multirate multistage bandpass filter designed in Complex Bandpass Filter Design. If you specify the center frequency and the decimation

Programmatically obtain the latency of an FFT HDL Optimized block in a model. You can use the latency value for delay matching of parallel data paths.

Generate and run the code of a parametric audio equalizer on ARM® Cortex-A processor while adjusting equalizer response in the SIMULINK® environment.

Use the Code Replacement Library (CRL) for ARM processor with DSP System object™. The model uses a MATLAB Function block that contains a dsp.FIRFilter System object to filter two sine waves

Generate and run optimized code for short-time spectral attenuation on the ARM Cortex-A processor. It includes using a switch to listen to the noisy and denoised signal in the SIMULINK®

Use the Code Replacement Library (CRL) for ARM processor with DSP blocks. The model uses the FIR filter block to filter two sine waves of different frequencies.

Use the Code Replacement Library (CRL) for ARM Cortex-A processor with DSP System object™. The example uses a dsp.FIRFilter System object to filter two sine waves of different frequencies.

Generate and run optimized code for real-time QRS detection of an electrocardiogram (ECG) signal on the ARM® Cortex®-A processor. It uses an ECG signal selector to allow users to choose ECG

Generate and run the optimized code of a parametric audio equalizer on ARM Cortex-M processor while adjusting equalizer response from within SIMULINK® environment. The optimized code

Use the Code Replacement Library (CRL) for ARM Cortex-M processor with DSP System object™. The example uses a dsp.FIRFilter System object to filter two sine waves of different frequencies.

Generate and run optimized code for real-time QRS detection of an electrocardiogram (ECG) signal on the ARM® Cortex®-M processor. It uses an ECG signal selector for choosing ECG signal

Use the Code Replacement Library (CRL) for ARM with DSP blocks. The model uses the FIR filter block to filter two sine waves of different frequencies.

Use the Code Replacement Library (CRL) for ARM with DSP System object™. The model uses a MATLAB Function block that contains a dsp.FIRFilter System object to filter two sine waves of

Use the Code Replacement Library (CRL) for ARM with DSP blocks. The model uses the fixed-point FIR filter block to filter two sine waves of different frequencies.

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