What is an alternative method(apart from 'Maxstep') to ensure ode45 does not take large time steps and ignore high frequency components in the forcing function?

1 view (last 30 days)
I am working on the response of vibrational energy harvesters to a very abrupt forcing function with many high-frequency components. The forcing signal is attached and it can be seen the peaks in the attached signal are very narrow and have high-frequency components.   To accurately reproduce the forcing signal, ode45 needs to take very small time steps.  But limiting the time steps via "MaxStep" option makes the simulation very very slow- I am talking snail- pace, nausea-inducing slow.
Are there any alternatives ? 
In response to the answer by Star Strider
I already pass an array for the Time vector. If I increase the sampling(increase the number of points), instead of MaxStep,
  1. The array becomes large
  2. The solution is very slow
Is there any way to make ode45 take large steps when the forcing is flat and take really small steps when the forcing derivatives are high(basically when the forcing has peaks) ?

Answers (2)

Star Strider
Star Strider on 8 Aug 2016
I would give it a vector of times (rather than a 2-element range) for ‘tspan’. It will report the integrated results at those times (or very close to them), requiring it to evaluate your function at those times. You can do this with the colon operator (:) or with linspace.
Example with linspace:
Ts = 0.001; % Sampling Interval
N = 1E4; % Number Of Points /Desired
tspan = linspace(0, 1, N)*Ts; % Time Vector
  2 Comments
Aditya Nanda
Aditya Nanda on 8 Aug 2016
Thank you. I already pass an array for the Time vector. If I increase the sampling(increase the number of points), instead of MaxStep,
  1. The array becomes large
  2. The solution is very slow
Is there any way to make ode45 take large steps when the forcing is flat and take really small steps when the forcing derivatives are high(basically when the forcing has peaks) ?
Star Strider
Star Strider on 9 Aug 2016
It depends on what you want to do with the integrated function. The image you attached is an EKG. If you want to do heart rate variability studies, the signal has to be regularly-sampled, just as would a recorded EKG trace. This is characteristic of all discrete biomedical signal processing techniques I’m aware of.
In the example I posted, I used a 1000 Hz sampling frequency. For EKG signal processing, any sampling frequency of 250 Hz or higher (sampling interval of at most 0.004 seconds) will work. This is due to the highest usable frequency in the majority of (and all normal) EKG records being about 100 Hz, requiring a Nyquist frequency (highest uniquely identifiable frequency in a sampled signal) of 200 Hz.

Sign in to comment.


Steven Lord
Steven Lord on 8 Aug 2016
Investigate if using one of the stiffer solvers will give better results for your application.

Community Treasure Hunt

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

Start Hunting!