This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Generate Code to Denoise a Signal

This example shows how to use MATLAB® Coder™ to generate executable code. The Wavelet Toolbox™ supports code generation for functions that support discrete wavelet transform (DWT), maximal overlap discrete wavelet transform (MODWT), maximal overlap wavelet packet transform (MODWPT), and denoising workflows. This example requires a MATLAB Coder license.

Define a function that uses wden to denoise a signal. You also specify the level to which to denoise the signal when you run the generated code.

  1. From the MATLAB command prompt, create the file, sigdenoise.m.

    edit sigdenoise
    If you do not have permission to write to the current working folder, change the current folder to one that is writable.

  2. Copy this sigdenoise function code into the sigdenoise.m file. Your file must include %#codegen to indicate that this function will generate code. coder.varsize indicates that the row vector input is not limited to a particular length.

    function xdenoise = sigdenoise(x,level)
    wname = 'sym4';
    xdenoise = wden(x,'sqtwolog','s','mln',level,wname);

  3. Save the file.

  4. At the MATLAB command line, use the codegen function to compile the sigdenoise function into a MEX file. You can use the -o option to specify the name of the executable. If you do not use the -o option, the generated MEX file has the same name as the original MATLAB file with _mex appended. You can include the -report option to generate a compilation report. This report shows the original MATLAB code and the associated files created during code generation. The -args option specifies the data types of the inputs required to run the generated code. In this case, a variable-size row vector and a scalar input are required.

    codegen sigdenoise.m -config:mex -args {coder.typeof(1,[1,inf],[false,true]),0}

  5. At the MATLAB command line, run the generated code on noisy Doppler data and denoise it to level three. Compare the original and denoised signals.

    load noisdopp;
    xden = sigdenoise(noisdopp,3);

For a list of Wavelet Toolbox functions supported for code generation and associated limitations, see Code Generation Support, Usage Notes, and Limitations. For more information on code generation, see Getting Started with MATLAB Coder (MATLAB Coder).

Was this topic helpful?