How to find the up-crossing of graph

6 Ansichten (letzte 30 Tage)
Oliver Goldsmith
Oliver Goldsmith am 13 Mär. 2017
Beantwortet: Star Strider am 13 Mär. 2017
Hey,
I have produced a graph with surface elevation of a water wave against time, this is shown in the following picture:
Is there a matlab function or way of reading the graph so that when Y=0 x=? and only output data when Y is going from negative to positive ie. when the line is up-crossing the x-axis? This will give me the period of the wave.
Unfortunately the data itself doesn't have y=0 it merely swaps from positive to negative and hence why reading it from the graph is necessary
Thank you for your time,
Oliver

Antworten (1)

Star Strider
Star Strider am 13 Mär. 2017
I have a little utility function that I wrote for just that purpose:
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
Because it can produce a false zero-crossing at the end of the vector, it may be necessary to discard the last index it returns.
To find the ‘exact’ zero-crossings from the indices it returns, a for loop and interp1 is the easiest way.
Example:
idx_vct = zci(your_y_data);
for k1 = 1:length(idx_vct)
idx_rng = (idx_vct(k1)-1:idx_vct(k1)+1);
x_zero(k1) = interp1(y(idx_rng), x(idx_rng), 0);
end
Note This is UNTESTED CODE. It should work, but may require modification. Be certain that ‘idx_vct(k1)-1’ and ‘idx_vct(k1)+1’ do not over-write the vector.

Community Treasure Hunt

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

Start Hunting!

Translated by