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

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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de En. de 2013
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.

Más respuestas (2)

Aniket
Aniket el 28 de En. de 2013
thanks Walter
and small doubt if the file is stereo then i have to use left and right coloumn and if file is mono then i can directly use fi as an input ?
Exactly:
fi = wavread('engine.wav')
Be sure to catch the frequency also, otherwise you cannot correlate the signal with the real time.
But a problem remains: You function to be integrated has discontinuities caused by the linear interpolation of a discontinuos perturbation. The stepsize control of ODE45 requires a smooth function, see: http://www.mathworks.com/matlabcentral/answers/59582#answer_72047. In consequence you can get 1. long runtimes and inaccurate results, 2. a warning and inaccurate results, or 3. an error, which stops the integration depending on the input data. From a scientific point of view, this is not a reliable calculation and therefore a waste of time.

6 comentarios

hello Jan
How could i catch the frequency of sound file ?
Jan
Jan el 29 de En. de 2013
Editada: Jan el 29 de En. de 2013
@Aniket: The documentation of wavread reveals the relevant details: doc wavread . While this should be easy, handling the discontinuities remains a serious problem.
Hello Jan
as per your comment i am facing same problem , its giving me inaccurate results . Then how should i solve this discontinuities? should i use simulink model for above equation instead of ode45 ? please give me suggestions and guidance.
Thanks in advance
Try a fixed step solver and define the steps such, that they happen at the discontinuous changes of the right hand side.
Means you are saying i have to use simulink ? because simulink using fixed step solver ...i have searched in matlab doc about fixed step but i am not getting any search result .

Iniciar sesión para comentar.

Categorías

Más información sobre Audio I/O and Waveform Generation en Centro de ayuda y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by