MATLAB: How could i give audio file as an external input to system in matlab

audioexternal input

Hello,
I have matlab code. Right now in this code i am giving fi as a external input that is fi = cos(10*Tspan) but instead of this how could i give audio file or *.wav file as an external input to this system ? I have read wavread function but not getting idea.
As per my perception, if i have for example engine.wav file then should i right fi = wavread(engine.wav) and this fi i can used as a external input ? or i have to write something extra for this ?
************************
function dz = myeqd(t,y,ti,fi)
dz = zeros(3,1);
mu=0.7;
r= sqrt(y(1)^2 + y(2)^2);
K=2;
F=interp1(ti,fi,t);
dz(1)= (mu – r^2)*y(1) – y(3)*y(2) +K*F;
dz(2) = (mu – r^2)*y(2) + y(3)*y(1);
dz(3) = (-K*F) * (y(2)/sqrt(y(1)^2 + y(2)^2));
**********************************
then call this function
********************************
Tspan= 0:0.01:500; % time vector
fi = cos(10*Tspan); % external perturbation
ti=Tspan;
[T,Y]=ode45(@(t,y) myeqd(t,y,ti,fi),Tspan,[1;1;30]);
plot (T,Y(:,3))
************************
thank you

Best Answer

Yes, you can use fi = wavread('engine.wav');
Do be careful, though: many audio files are stereo, and so wavread() would result in two columns but your code appears to be expecting only one column.