Why t_tide prediction is offseted?
26 views (last 30 days)
Show older comments
Hi, i'm trying to use t_tide_v1.4beta using matlab R2016a in 2 ways like in t_tide example but the result of the harmonic constants is not similar and the prediction is not similar between prediction also offseted to the observation data. Help me please. Herewith the code and the data that I use.
Code:
clear
clc
%format LONGG
%load t_example
% load data excel
data = readtable('D:\Test\T_Tide\t_tide_v1.4beta\kmna_wnan.xlsx');
time_axis = datetime(data.waktu);
data_time = datenum(time_axis);
obs_value = data.ukuran;
% Analisis Harminik
%---------------------------------------------------------------------------
% Way 1
% analisys
[NAME,FREQ,TIDECON,XOUT] = t_tide(obs_value,'interval',1,'start',data_time(1),'latitude',-3.66295,'synthesis',1);
% prediction
YOUT=t_predic(data_time,NAME,FREQ,TIDECON,'latitude',-3.66295,'synthesis',1);
% Way 2
% analisys
[HarKons,XOUT2]=t_tide(obs_value,'interval',1,'start',data_time(1),'latitude',-3.66295,'rayleigh',1,'synthesis',1);
% prediction
% YOUT=T_PREDIC(TIM,TIDESTRUC,...)
YOUTHarKons1=t_predic(data_time,HarKons,'latitude',-3.66295,'synthesis',1);
YOUTHarKons2=t_predic(data_time,HarKons);
%% visualisasi
figure(1)
plot(time_axis,obs_value,'b','LineWidth',1.5); hold on
plot(time_axis,XOUT,'r--','LineWidth',1.5); hold on
plot(time_axis,YOUT,'c.','LineWidth',1.5); hold on
plot(time_axis,YOUTHarKons1,'kx','LineWidth',1.5); hold on
plot(time_axis,YOUTHarKons2,'ko','LineWidth',1.5); hold on
title('Tidal Elevation','FontSize',14,'fontWeight','b')
legend({'obs_value', 'XOUT', 'YOUT', 'YOUTHarKons1', 'YOUTHarKons2'},'FontSize', 10, 'FontWeight', 'bold', 'Location', 'northeastoutside');
xlabel('Time','FontSize',14,'FontWeight','b')
ylabel('Elevation (m)','FontSize',14,'FontWeight','b')
% Format sumbu X agar menampilkan tanggal/waktu
% datetick('x', 'dd/mm/yyyy HH:MM:ss', 'keepticks', 'keeplimits')
grid on
Tidal graph obs_value and prediction:

Data:
0 Comments
Answers (1)
William Rose
on 31 Dec 2025 at 18:50
The predictions from t_tide do not include a DC (i.e. zero-frequency) term. Therefore the t_tide predictions have zero mean value, since they are a sum of sinusoids with non-zero frequency. You can see this in the original article by the authors of t_tide, here. Compare panels A and B of Figure 1 in the article. The data to be fitted, in panel A, has non-zero mean value. The prediction in panel B has mean value equal to zero.
You can compute the mean value of your sample data, then add it to the t_tide prediction, so that the t_tide prediction better. If you publish this, explain what you have done. Or you can subtract the mean value from your signal before you plot it, so that it corresponds to the t_tide prediction.
Good luck with your research.
2 Comments
William Rose
on 4 Jan 2026 at 21:28
It sounds like you have solved your problem with your Way 1 method.
I am not sure why your Way 2 method is not giving you the results you want.
I do not like to modify function t_tide(), because it I did not write t_tide(), so I do not fully understand it, and it interacts with other functions that are part of the t_tide package. Any changes I make could have unexpected effects. Therefore I do not modify t_tide(). I do want the predictions to look like the data, so I compute the mean of the good data points (excluding NaNs) and I add the mean to xout when plotting the results. The example below, which is runnable in thre Matlab Answers window, shows this. Scroll to bottom to see the plot of measured and predicted tide data.
load('data2share');
% Vector elev is from satellite data, and includes NaNs.
% tInterval is the time between satellite passes.
%% Identify missing points
gd=find(~isnan(elev)); % indices of good points
%% Compute mean
meanElev=mean(elev(gd)); % mean of observations
Next: analyze the data.
% Analyze tide components
unzip('tide3') % reference data used by t_tide
[tidestruc,xout]=t_tide(elev,...
'interval',tInterval, ... % sampling interval
'error','wboot'); % CI from white noise model
Next: Plot results. Add meanElev to xout when plotting.
% Plot elevation versus time, observed & fitted & residuals
figure;
plot(obsTime,elev,'-b.',...
obsTime,xout+meanElev,'rx', obsTime,elev-(xout+meanElev),'-g+')
title([filename,': Elevation versus Time'],'Interp','none')
xlabel('Date'); ylabel('Elevation (m)')
grid on; legend('Observed','Fitted','Residual')
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox 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!



