Line 1: | Line 1: | ||
− | + | =Application of LTI Systems and Convolution in Matlab= | |
− | =Background= | + | ==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. | 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. | ||
Line 7: | Line 7: | ||
the experiments are a laptop with microphone, Matlab student edition or better, and a couple everyday items. | the experiments are a laptop with microphone, Matlab student edition or better, and a couple everyday items. | ||
− | =Audio Impulse Response= | + | ===Audio Impulse Response=== |
We have seen impulse responses expressed as mathematical functions such as <math>2^{-n}u[n]</math>. 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. | We have seen impulse responses expressed as mathematical functions such as <math>2^{-n}u[n]</math>. 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. | ||
Line 16: | Line 16: | ||
==The Code== | ==The Code== | ||
− | Below are code listings for the required Matlab functions. | + | Below are line numbered code listings for the required Matlab functions. |
− | + | Function for recording audio. | |
+ | <code><syntaxhighlight lang="MATLAB" line='line'> | ||
+ | function [ ] = recordToFile( inFileName, Fs, nbits, seconds ) | ||
+ | %record audio to a file with specified name, record for specified time, | ||
+ | %and at the sampling frequency and bit size (8,16,or 24) | ||
+ | recordObj = audiorecorder(Fs, nbits, 1); | ||
+ | record(recordObj); | ||
+ | pause(seconds); | ||
+ | stop(recordObj); | ||
+ | audiowrite(inFileName, getaudiodata(recordObj), Fs); | ||
+ | end | ||
+ | </syntaxhighlight></code> | ||
+ | ''[[File:recordToFile.m|Source]]'' |
Revision as of 21:13, 2 December 2018
Contents
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.
function [ ] = recordToFile( inFileName, Fs, nbits, seconds )
%record audio to a file with specified name, record for specified time,
%and at the sampling frequency and bit size (8,16,or 24)
recordObj = audiorecorder(Fs, nbits, 1);
record(recordObj);
pause(seconds);
stop(recordObj);
audiowrite(inFileName, getaudiodata(recordObj), Fs);
end