Find Peaks error - Expected X to be strictly increasing

60 Ansichten (letzte 30 Tage)
Lee Madden
Lee Madden am 7 Apr. 2021
Attempting to generate a waveform similar to the image, ploting displacement against time
However, getting an error where findpeaks needs x to be increasing
How would I get around this error without altering the displacement data which cant be strictly increasing?
Code Below:
%Averaging I_0
idxI0 = find(I_0_displacement == min(I_0_displacement)); %first response peak index
averageLineI0 = mean(I_0_displacement(idxI0:end)); %average after 1st true peak
[pks_I0, locs_I0] = findpeaks (I_0_displacement(idxI0:end), I_0_time(idxI0:end),'NPeaks',2, 'MinPeakHeight', averageLineI0); % find the first two peaks x, y values
[nRowsI0, ~] = size(I_0_time); % for adding the average value line
%I = I0:
figure(1)
hold on
plot(I_0_time, I_0_displacement, I_0_time, averageLineI0*ones(nRowsI0,1)); % plot the response and average line
plot(locs_I0, pks_I0, 'ko'); % plot the average line
%create lines which stem from the average line to the peak values:
[~,I0_c1] = size(averageLineI0:pks_I0(1));
[~,I0_c2] = size(averageLineI0:pks_I0(2));
plot(ones(1,I0_c1)*locs_I0(1), averageLineI0:pks_I0(1), ones(1,I0_c2)*locs_I0(2), averageLineI0:pks_I0(2));
title('I0 Displacement VS. Time') % add a relevant title
ylabel('Displacement(mm)') % add y axis label - check that you're plotting positive time, as per the note above!
xlabel('Time(s)') % add x axis label - check that you're plotting displacement in mm
legend('Displacement', 'Average Line', 'peak values', 'x1', 'x2')
axis([0 10 -60 0])
hold off
Screenshot:

Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 7 Apr. 2021
Check that your X-variable is actually monotonically increasing (you might have replicate points, which then messes everything up for you):
Increasing = all(diff(I_0_time(idxI0:end))>0)
In the case you have replicate X-values you'll have to resolve that problem. That is simple if the Y-values are identical then just use unique to find the unique X-values and their indices and use those indices to select the corresponding Y-values. If the Y-values aren't identical you'll have to use your best judgement - perhaps taking the average?
HTH

Kategorien

Mehr zu Vibration Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by