Solving a second order differential equation with matlab.

4 vues (au cours des 30 derniers jours)
Marius Turcan
Marius Turcan le 14 Déc 2018
Modifié(e) : madhan ravi le 15 Déc 2018
Hey,
I wanted to plot a second order differential equation in Matlab to see how it would look. The equation is the following:
y = x + 2*cos(omega)*y'-y''
This equation corresponds to an IIR filter with the poles on the unit circle. I will be using it to generate harmonic oscillations.
"x" only gives a unit impulse, and omega = 2*pi*(f0/fs), and is used to control the oscillations.
Please show me what I should write to be able to see these oscillations in Matlab.
Thanks in advance.

Réponse acceptée

madhan ravi
madhan ravi le 14 Déc 2018
Modifié(e) : madhan ravi le 14 Déc 2018
syms y(x)
dy=diff(y);
dy2=diff(y,2);
omega=5; %your value acheived by 2*pi*(f0/fs) formula
ode=y == x + 2*cos(omega)*dy-dy2 ;
vars = y(x);
V = odeToVectorField(ode)
M = matlabFunction(V,'vars', {'x','Y'})
interval = [0 10]; %time interval
y0 = [0 0]; %initial conditions
ySol = ode45(M,interval,y0);
tValues = linspace(interval(1),interval(2),1000);
yValues = deval(ySol,tValues,1); %number 1 denotes first solution likewise you can mention 2 for the next solution
plot(tValues,yValues)
hold on
yValues = deval(ySol,tValues,2);
plot(tValues,yValues,'r')
  2 commentaires
Marius Turcan
Marius Turcan le 15 Déc 2018
Thank you for your answer.
It is working, and producing the same plot you've provided.
I have a follow-up question, which is how would I go from here if I want to see a continuous evaluation of the oscillations produced, the same way you would see on an oscilloscope?
Would I be better off implementing the corresponding filter in Simulink and viewing that way?
madhan ravi
madhan ravi le 15 Déc 2018
Modifié(e) : madhan ravi le 15 Déc 2018
Would I be better off implementing the corresponding filter in Simulink and viewing that way?
I have no experience with simulink.. but I am pretty sure it's more handy to simulate

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Modeling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by