Doing Fourier transform (FFT) of the output of an ode45 solution and subsequent plotting in the frequency domain.
3 views (last 30 days)
Show older comments
I want to do the FFT of the output of an ode45 solution and then plot it in the frequency domain.
The solution of the ODE is sinusoidal with specific frequency but upon transforming (FFT) the solution and then plotting in the frequency domain, I am getting spikes at different frequencies. The issue seems to be with the choice of sampling frequency for FFT. Please suggest.
0 Comments
Accepted Answer
Star Strider
on 19 Aug 2022
The fft function requires that the time domain signal be samoled at regular intervals. The numerical dddifferential equation integrators will produce a time vector with irregular intervals if you only give it a ‘tspan’ argument with 2 elements, however it will produce results at uniform spacing if ‘tspan’ is a vector of more than two elements. Taht can then be used with fft.
de = @(t,x) [x(1); 1./(5 - x(1))];
ic = [1 1];
tspan = [0 5];
[T,Y] = ode45(de, tspan, ic);
figure
plot(T,Y,'.-')
grid
tspan = linspace(0, 5, 50);
[T,Y] = ode45(de, tspan, ic);
figure
plot(T,Y,'.-')
grid
.
2 Comments
Star Strider
on 19 Aug 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
