Integration drift with numerical simulations
Show older comments
Hi Guys
I have solved a system of differential equations, whereby some of the variables are presenting integration drift in the results.
I have attached a spreadsheet with the results of one of the variables (theta) note that the time component was exluded to keep the file small. The time increments are 0.0001seconds with t starting at 0.
The plot of the results is presented below.
The inital conditions of the problem has theta = 0.1, which is correct when reviewing the data in the spreadsheet.
I have used the code below to process the data, however upon processing the data the inital condition is no longer true as the value is no longer 1. Note that the code does not present the data being read from the excel file as it already exists in a variable (theta).
Could someone please give me some advice on how one could accurately process the data?
T = detrend(theta,1);
figure(33)
plot(t,T)
Fs = 1/inc;
Fc = 1/(Fs/2);
[b a] = butter(4,Fc,'high');
T = filtfilt(b,a,T);

3 Comments
Mathieu NOE
on 26 Oct 2021
hello
so if I understand correctly , you want to apply a high pass filter but keep IC = 0.1 even on the filtered data ?
so far a modified code produces this plot and yes the initial conditions differ between raw and filtered data
note that filtfilt do not creat any phase distorsion (a contrario from filter) but does not garantee that the IC are the same - clearly not here
my test code so far
theta = importdata('theta.txt');
theta = theta.data;
inc = 0.0001; % second
samples = length(theta);
t = inc*(0:samples-1);
Fs = 1/inc;
Fc = 1/(Fs/2);
[b, a] = butter(2,Fc,'high');
T = filtfilt(b,a,theta);
plot(t,theta,t,T)
legend('raw','HP filtered')


Mishal Mohanlal
on 26 Oct 2021
Mathieu NOE
on 26 Oct 2021
hello Mishal
well doing filter can alter initial condition
if you use filter, this is only a forward time filter and you see the IC are kept the same so this is fine , but this way of doing filtering will cause a good amount of phase lag as will do any filter
if you use filtfilt , this applies the filtering both in forward and backward time axis, so this will cancel the phase lag and keep your signals time aligned , but the code cannot garantee that IC will be kept exact the same.
I will suggest you a solution in the answer section
see if it fills your needs and if you accept it
Accepted Answer
More Answers (0)
Categories
Find more on Multirate Signal Processing 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!
