Saturday, November 30, 2013

DSP in MATLAB®: Echo and Reverberation Part 1

Digital Signal Processing (DSP) is an interesting discipline as far as applications are concerned. This is one of the disciplines that came into academics from industry, not vice versa.

I'll discuss about the most common application of digital audio signal processing in the audio domain, i.e. echo generation. This is implemented to give a pleasant sound effect to a very dry sound, e.g. at home, listening to an orchestra would be boring (unless you have a big home!). But, a visit to the theater will always give a more soothing, or rather pleasant sound effect to harmonic instruments rather than at home. This is due to the architectural acoustics of the theater, which creates a calculated amount of reverberation.

We all know about sound effects used in sound card software (e.g. Realtek HD Audio Manager) or media players (e.g. VLC media player) and even sound mixing software (e.g. VirtualDJ). In this post, I will discuss the insides of reverberation used in these software on a basic level.

Please note that some software mention reverberation settings as "spatializer", because it generates a false impression of a room whose parameters are set by the user.

Note: Echo is the reflection of sound which returns after a longer period of time like shouting in the hills. Reverberation is the effect which we look for, to improve music quality ("the orchestra in the theater" stuff). Essentially, a reverberation elongates the perception of the sound. For human ear, this period is well within 1/15th of a second.


Method 1: Using delay blocks in Simulink

We know that whether it is an echo or a reverberation, it is essentially a damped delay of the original sound data. Using this fact, we can implement an echo or a reverberation generator using Simulink.

The block diagram can be made as shown below in Simulink using the following blocks:
  • Adder 
  • From multimedia file
  • To output device
  • Delay
  • Gain
  • Unbuffer 
Though this is taken from an example from MATLAB, this design shown here is more improvised, as it provides multipath reflection simulation. Also, a switch may be provided to compare the results of the original sound and the processed sound.

The gain block provides negative feedback, and stabilizes the system from unbounded output, which will result into noise. One may also set a parameter in the "Adder" block, which prevents overflow of the output, by saturating it to a certain maximum value.

The model file link is provided here.

One should also take note about the block "From multimedia file". One can select any file from the computer for processing. This block reduces the burden of decoding any file, may it be MP3, WAV, etc., and provides data in a stream form in real time. But, audio files are mostly frame coded, i.e. number of samples are grouped in one frame. These should be unbuffered to process them in Simulink as some blocks are inconsistent with frame based simulation (e.g. To output device). 

Also, considering the delay to be set, it should be calculated on the basis of the number of samples that pass through the circuit for that period. e.g. if you need a delay of 0.15 seconds, and the sample rate is 44100Hz, then you should place a delay of 44100*0.15= 6615 samples. The delays can be set to give a harmonic illusion of reflection and gain should be set for the same.

Method 2 will be discussed in my next post. See you there...