This is machine translation

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

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

Reverberation Using MATLAB Classes

This example shows how to 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.


There are no prerequisites for this example.

Create a New Folder and Copy Relevant Files

The following code will create a folder in your current working folder (pwd). The new folder will only contain the files that are relevant for this example. If you do not want to affect the current folder (or if you cannot generate files in this folder), you should change your working folder.

Run Command: Create a New Folder and Copy Relevant Files


Implementing a Simple Reverberation Effect. There are many ways to implement a reverberation effect with different characteristics. In terms of audio quality, this is not an advanced effect, but shows the capabilities of using MATLAB classes with MATLAB Coder.

This reverberation effect is implemented based on the following block diagram:

The diagram shows only the first delay line. Imagine another seven delay lines being repeated in the diagram but each delay line has an individual delay and associated feedback gain block. The Householder reflection (i.e. hhreflect function) is essentially mixing/permuting the signals without changing the energy of the total signal. Therefore, we are essentially duplicating the incoming signal and feeding it back with small time displacements. The result is a reverberation effect.

Files Used

  • reverb_test.m: Main file testing the reverberation effect

  • do_reverb.m: Function abstraction of the Reverb class

  • Reverb.m: Effect implementation implemented as a MATLAB class

  • Delay.m: Delay effect for Reverb.m implemented as a MATLAB class

  • hhreflect.m: Householder reflection for Reverb.m

  • get_prime.m: Function to compute prime numbers (for Reverb.m)

  • speech_dft.mat: Test sample file

Generate a MEX Function

codegen do_reverb

Run the MEX Function

This processes the sample file (speech_dft.mat), applies the reverberation effect, and outputs the result to the computer's audio output.

Running time = 20 milliseconds

Generate a Faster MEX Function

Disable the integrity checks (e.g. out of bound checks for matrices) to obtain a faster but potentially unsafe MEX function.

cfg = coder.config;
cfg.IntegrityChecks = false;
codegen -config cfg do_reverb

Retry the MEX Function

Running time = 8 milliseconds


Remove files and return to the original folder

Run Command: Cleanup

Was this topic helpful?