Documentation Center

  • Trial Software
  • Product Updates

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.

Prerequisites

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

coderdemo_setup('coderdemo_reverb');

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

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.

reverb_test;
Running time = 22 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

reverb_test;
Running time = 41 milliseconds

Cleanup

Remove files and return to the original folder

Run Command: Cleanup

cleanup
Was this topic helpful?