Revision as of 22:21, 2 December 2018 by Glake (Talk | contribs)

Application of LTI Systems and Convolution in Matlab

Background

Often music groups would like to make their studio recordings sound as if they were played in a live venue. One method to achieve this is to convolve the audio recording with an impulse response taken from the concert venue, or another location with similar acoustics.

Convolution may also be used in the same way to alter your voice which will be demonstrated below. All you need to try out the experiments are a laptop with microphone, Matlab student edition or better, and a couple everyday items.

Audio Impulse Response

We have seen impulse responses expressed as mathematical functions such as $ 2^{-n}u[n] $. Such functions we compute convolutions with in class may model actual impulse responses such as the fading echo heard after clapping in a concert hall or ringing of a gong after being struck. To obtain a good impulse response recording, audio data should include the sound from just after the impulse until it has died away sufficiently. Distortion of the output may result from convolving with an incorrectly recorded impulse response.


Voice Effect Experiment

I will demonstrate the procedure for this Matlab experiment by attempting to make my voice sound as if I am speaking into an empty cactus cup (large plastic cup), without actually speaking into it.

The Code

Below are line numbered code listings for the required Matlab functions.

Function for recording audio.

  1. function [ ] = recordToFile( inFileName, Fs, nbits, seconds ) 
  2. %record audio to a file with specified name, record for specified time, 
  3. %and at the sampling frequency and bit size (8,16,or 24) 
  4. recordObj = audiorecorder(Fs, nbits, 1); 
  5. record(recordObj); 
  6. pause(seconds); 
  7. stop(recordObj); 
  8. audiowrite(inFileName, getaudiodata(recordObj), Fs); 
  9. end

Function for trimming audio from the back end

  1. function [ lengthSec ] = trimAudioEnd( inFileName, seconds )
  2. %trimAudioEnd: truncate audio file by x seconds, output the 
  3. %file pointer and the length in seconds of audio contained in the file now.
  4. %param inFileName: the name of the audiofile
  5. %param seconds: seconds of audio to trim from the end
  6. [y,fs] = audioread(inFileName);
  7. if mod(seconds*fs, 1) ~= 0
  8.     error('sample frequency times seconds must be an integer')
  9. end
  10. samples = [1, length(y) - (seconds*fs)];
  11. [y1,fs] = audioread(inFileName, samples);
  12. audiowrite(inFileName, y1, fs);
  13. lengthSec = length(y1) / fs;
  14. end

Alumni Liaison

Questions/answers with a recent ECE grad

Ryne Rayburn