Borrar filtros
Borrar filtros

RECONSTRUCTED/PREDICTED CURVE AND ORIGINAL CURVE DISSIMILARITY

4 visualizaciones (últimos 30 días)
Hello everyone. i want to analyse my tidal data in T-Tide. i want to do simple harmonic analysis, velcoity, acceleration, residual, and check anomaly. but in plot there is error in the predicted and origibal data they do not looks similar and also in other plots as well. kindly anyone help me to solve the issue below is my code i have created. pls note i am new to MATLAB. anyone guide where is mistake in the code. Here is the code
% Step 1: Load and preprocess the tidal data from xlsx file
filename = 'DATA1.xlsx'; % Specify the filename of your xlsx file
% Read the xlsx file using readtable
data = readtable(filename);
% Extract the date and time columns as MATLAB datetime
DT = data.DT; % Assuming the date and time column is named 'DT' in the xlsx file
% Extract the tidal height column
H = data.H; % Assuming the tidal height column is named 'H' in the xlsx file
% Step 2: Convert datetime to decimal days format
time = datenum(DT); % Convert datetime to decimal days format
% Remove NaN values from both DT and H
nanIndices = isnan(H) | isnan(time);
time = time(~nanIndices);
H = H(~nanIndices);
% Step 3: Apply moving average filter
windowSize = 24; % Choose an appropriate window size for the moving average
H_filtered = movmean(H, windowSize);
% Step 4: Perform harmonic analysis using T_Tide toolbox
t_pred = (time - time(1)) * 24; % Convert time to hours (T_Tide uses hours)
% Perform harmonic analysis using T_Tide toolbox
[tidecon, ~] = t_tide(H_filtered, 'interval', t_pred(2) - t_pred(1));
% Step 5: Reconstruct the tidal signal
u_recon = zeros(size(t_pred)); % Initialize reconstructed signal array
% Iterate over each constituent and add to the reconstructed signal
for i = 1:length(tidecon.name)
u_recon = u_recon + tidecon.tidecon(i, 1) * cos((2 * pi / tidecon.tidecon(i, 3)) * (t_pred - tidecon.tidecon(i, 4)));
end
% Step 6: Smoothing the reconstructed signal
windowSize = 10; % Adjust the window size as needed
u_recon_smoothed = movmean(u_recon, windowSize);
% Step 7: Compute velocity and acceleration from the smoothed reconstructed signal
% Interpolate the reconstructed signal to obtain evenly spaced time values
numPoints = 1000; % Number of Points for Interpolation
t_interp = linspace(t_pred(1), t_pred(end), numPoints);
u_interp = interp1(t_pred, u_recon_smoothed, t_interp);
% Compute velocity and acceleration using interpolated data
dt = t_interp(2) - t_interp(1);
velocity_interp = gradient(u_interp, dt);
acceleration_interp = gradient(velocity_interp, dt);
% Resample the velocity and acceleration to match the original time values
velocity_smoothed = interp1(t_interp, velocity_interp, t_pred);
acceleration_smoothed = interp1(t_interp, acceleration_interp, t_pred);
% Compute residuals
residual = H_filtered - u_recon_smoothed;
% Calculate anomalies
mean_H = mean(H);
anomalies = H - mean_H;
% Set figure size
figure('Position', [100, 100, 800, 800]);
% Plot original data
subplot(4, 2, [1, 2]);
plot(DT, H_filtered, 'b.', 'LineWidth', 1.5);
xlim([DT(1) DT(end)]); % Set the x-axis limits;
ylabel('Tidal Height');
title('Original Data');
% Plot reconstructed signal
subplot(4, 2, 3);
plot(DT(~nanIndices), u_recon_smoothed, 'r.', 'LineWidth', 1.5);
xlim([DT(1) DT(end)]); % Set the x-axis limits
ylabel('Tidal Signal');
title('Reconstructed Signal');
% Plot velocity
subplot(4, 2, 4);
plot(DT(~nanIndices), velocity_smoothed, 'm.', 'LineWidth', 1.5);
xlim([DT(1) DT(end)]); % Set the x-axis limits
ylabel('Velocity');
title('Tidal Velocity');
% Plot acceleration
subplot(4, 2, 5);
plot(DT(~nanIndices), acceleration_smoothed, 'c.', 'LineWidth', 1.5);
xlim([DT(1) DT(end)]); % Set the x-axis limits
ylabel('Acceleration');
title('Tidal Acceleration');
% Plot residuals
subplot(4, 2, 6);
plot(DT(~nanIndices), residual, 'g.', 'LineWidth', 1.5);
xlim([DT(1) DT(end)]); % Set the x-axis limits
ylabel('Residual');
title('Residual (Prediction Error)');
% Plot anomalies
subplot(4, 2, [7, 8]);
plot(DT(~nanIndices), anomalies, 'r.', 'LineWidth', 1.5);
xlim([DT(1) DT(end)]); % Set the x-axis limits
ylabel('Anomalies');
title('Tidal Height Anomalies');
% Adjust the subplot layout
sgtitle('Tidal Analysis with Anomalies', 'FontSize', 14);
  1 comentario
Subash Mylraj
Subash Mylraj el 2 de Ag. de 2023
Kindly attach the file "DATA1.xlsx" or some other sample file so that I can reproduce the problem at my end.

Iniciar sesión para comentar.

Respuesta aceptada

Aditya
Aditya el 14 de Nov. de 2023
Hi Shoukat,
I understand that you are facing error in plotting the predicted and orignal data. Here is code that might help you.
% Step 1: Load and preprocess the tidal data from xlsx file
filename = 'DATA1.xlsx'; % Specify the filename of your xlsx file
% Read the xlsx file using readtable
data = readtable(filename);
% Extract the date and time columns as MATLAB datetime
DT = data.DT; % Assuming the date and time column is named 'DT' in the xlsx file
% Extract the tidal height column
H = data.H; % Assuming the tidal height column is named 'H' in the xlsx file
% Step 2: Convert datetime to decimal days format
time = datenum(DT); % Convert datetime to decimal days format
% Remove NaN values from both DT and H
nanIndices = isnan(H) | isnan(time);
time = time(~nanIndices);
H = H(~nanIndices);
% Step 3: Apply moving average filter
windowSize = 24; % Choose an appropriate window size for the moving average
H_filtered = movmean(H, windowSize, 'omitnan'); % Add 'omitnan' to handle NaN values
% Step 4: Perform harmonic analysis using T_Tide toolbox
t_pred = (time - time(1)) * 24; % Convert time to hours (T_Tide uses hours)
% Perform harmonic analysis using T_Tide toolbox
tidecon = t_tide(H_filtered, 'interval', t_pred(2) - t_pred(1)); % Remove the second output argument (~)
% Step 5: Reconstruct the tidal signal
u_recon = t_pred * 0; % Initialize reconstructed signal array
% Iterate over each constituent and add to the reconstructed signal
for i = 1:length(tidecon.name)
u_recon = u_recon + tidecon.tidecon(i, 1) * cos((2 * pi / tidecon.tidecon(i, 3)) * (t_pred - tidecon.tidecon(i, 4)));
end
% Step 6: Smoothing the reconstructed signal
windowSize = 10; % Adjust the window size as needed
u_recon_smoothed = movmean(u_recon, windowSize, 'omitnan'); % Add 'omitnan' to handle NaN values
% Step 7: Compute velocity and acceleration from the smoothed reconstructed signal
% Interpolate the reconstructed signal to obtain evenly spaced time values
numPoints = 1000; % Number of Points for Interpolation
t_interp = linspace(t_pred(1), t_pred(end), numPoints);
u_interp = interp1(t_pred, u_recon_smoothed, t_interp, 'linear', 'extrap'); % Add interpolation method and extrapolation
% Compute velocity and acceleration using interpolated data
dt = t_interp(2) - t_interp(1);
velocity_interp = gradient(u_interp, dt);
acceleration_interp = gradient(velocity_interp, dt);
% Resample the velocity and acceleration to match the original time values
velocity_smoothed = interp1(t_interp, velocity_interp, t_pred, 'linear', 'extrap'); % Add interpolation method and extrapolation
acceleration_smoothed = interp1(t_interp, acceleration_interp, t_pred, 'linear', 'extrap'); % Add interpolation method and extrapolation
% Compute residuals
residual = H_filtered - u_recon_smoothed;
% Calculate anomalies
mean_H = mean(H);
anomalies = H - mean_H;
% Set figure size
figure('Position', [100, 100, 800, 800]);
% Plot original data
subplot(4, 2, [1, 2]);
plot(DT(~nanIndices), H_filtered, 'b.', 'LineWidth', 1.5); % Use the non-NaN indices for plotting
xlim([DT(1) DT(end)]); % Set the x-axis limits;
ylabel('Tidal Height');
title('Original Data');
% Plot reconstructed signal
subplot(4, 2, 3);
plot(DT(~nanIndices), u_recon_smoothed, 'r.', 'LineWidth', 1.5); % Use the non-NaN indices for plotting
xlim([DT(1) DT(end)]); % Set the x-axis limits
ylabel('Tidal Signal');
title('Reconstructed Signal');
% Plot velocity
subplot(4, 2, 4);
plot(DT(~nanIndices), velocity_smoothed, 'm.', 'LineWidth', 1.5); % Use the non-NaN indices for plotting
xlim([DT(1) DT(end)]); % Set the x-axis limits
ylabel('Velocity');
title('Tidal Velocity');
% Plot acceleration
subplot(4, 2, 5);
plot(DT(~nanIndices), acceleration_smooth
If this does not help please provide me with the "DATA1.xlsx" file.
Hope this helps.
Thanks and Regards,
Aditya Kaloji

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by