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.
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.
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.
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
This processes the sample file (speech_dft.mat), applies the reverberation effect, and outputs the result to the computer's audio output.
Running time = 53 milliseconds
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
Running time = 18 milliseconds
Remove files and return to the original folder