MATLAB: Phase shifting graphs and limit range of x-axis

joining curve lines limiting x-axisphase shift

Hi there, I'm currently making my dissitation on free-stream velocity fluctuation in tides. Spring tides (highest velocity) occur twice in a lunar cycle and neap tides (lowest velocity) occur also twice in a lunar cycle. Lunar cycles occur every 29.53 approximately with Spring tides and neap tides a quarter of a cycle apart. I'm trying to simulate the the fluctuation, however I've come across a couple of problems. There is phase shift which I haven't included because shifting the initial graph would also mean changing the initial amplitude. I've tried doing It this way but I just get further problems later on. I've also chosen to further the range by adding an additional quarter forward of time and before x = 0 in case of phase shift. What I want to do is first of all eliminate the problem of the reflected wave before x=0 and the wave after x=0 not being joined together, secondly shift the wave by E(k)/24, and thirdly limit the x-axis between 0 and 29.53 so that the wave can only be seen between 0 and 29.53. I've attached the Excel file that's imported.
[data, titles, r]=xlsread('Tidal Sites.xlsx');
A=data(:,4); %Amplitude
B=data(:,10); %Exponential decrease
C=data(:,11); %Frequency
E=data(:,6); %Number of hours difference spring tide is relative to dover
F=titles(:,2); %Site name
for k=1:length(E)
if ~isnan(E(k))
x1=linspace(0, 7.3826475, 10000);
y1=det(A(k))*((exp(1).^(det(-B(k)).*x1))).*cos((det(C(k)).*x1));
figure, plot(x1,y1), hold on
x2 = x1(end) + cumsum(fliplr(diff(x1)));
y2 = fliplr(y1(1:end-1)); %Reflection after the first quarter of lunar cycle
x3 = x2(end) + cumsum(fliplr(diff(x2)));
y3 = fliplr(y2(1:end-1));
x4 = x3(end) + cumsum(fliplr(diff(x3)));
y4 = fliplr(y3(1:end-1)); %2 more reflections to give lunar cycle
x5 = x4(end) + cumsum(fliplr(diff(x4)));
y5 = fliplr(y4(1:end-1)); % an additional quarter of cycle to make up for phase difference FORWARD
x6 = 0 - cumsum(fliplr(diff(x1)));
y6 = y1(1:end-1); %an additional quarter of cycle to make up for phase difference BEHIND
x = horzcat(x1, x2, x3, x4, NaN, x5, NaN, x6);
y = horzcat(y1, y2, y3, y4, NaN, y5, NaN, y6);
plot(x, y), hold on
title(F(k+1))
xlabel('Time (days)')
ylabel('Free-stream velocity (m/s)')%Problem arises at x = 0 where the reflected curve lines don't join
end
end

Best Answer

M - you mention the problem of the reflected wave before x=0 and the wave after x=0 not being joined together. If I iterate through the above code, the x6 is an array of negative elements in decreasing order from -0.12 to -7.5. Why have you appended this to the end of x and not to the beginning like
x = horzcat(flip(x6), x1, x2, x3, x4, NaN, x5, NaN);
y = horzcat(flip(y6), y1, y2, y3, y4, NaN, y5, NaN);
That will "bridge the gap" around x=0.
As for shifting the wave by E(k)/24, what do you mean by that? Your code does
x6 = E(1)/24 - cumsum(fliplr(diff(x1)));
for every k, so that seems not to be correct. And you are only applying the above to x1. Why not x2, x3, etc.?
And, to limit the x-axis to a fixed interval, just use xlim as
xlim([0 29.53]);
Though by doing this, you will no longer observe the problem of the wave not being joined together around 0.
I think that you may want to revisit your application of the "shift" and the values in E.