Finding peak value and peak arrival time from a time-domain plot and store it into a matrix.

I have 360 differential signals to be processed through SVM. How do I extract peak value and peak arrival time from time-domain plot of each signal and store it in a single matrix? Below is my code.
% load a .mat file
load ('Defect_Signals_with_Labels.mat');
fs = 100000;
for j = 1:360
x = SurfaceDifferential(:,j);
% set time to be in milliseconds
time = ( 0: length(x)-1) / fs;
% plot frequency in time domain
figure(2);
plot(time, x);
xlabel('Time (s)');
ylabel('Magnitude (Gauss)');
grid on;
end

 Risposta accettata

Hi Syed,
are you looking for the max value and its index ?
peakValues = NaN(360, 2); %column 1 is peak value, column 2 is arrival time
for j = 1:360
% Extract the time-series data
x = SurfaceDifferential(:,j);
% set time to be in milliseconds
time = ( 0: length(x)-1) / fs;
%extract max and its location from the timeseries data
[xMax, xIdx] = max(x);
peakValues(j,1) = xMax;
peakValues(j,2) = time(xIdx); %to get the value in milliseconds
%plot...
end
best, Sandro

4 Commenti

Hai Sir,
Yes. I wanted to get the max value for the frequency. And for time, I wanted to get the rise time if possible. Sorry for the misleading title. It should be the rise time.
Hello,
from my personal experience, getting the correct rise time is not as trivial as identifying the max value (with a sample to sample resolution, of course). As I have no clue about how your data look like I can simply propose you an approach.
Assuming the event you are interested in stands out clearly from the background noise, I would calculate the first derivative of your signal and identify the rising moment.
Try to calculate diff(x) and see by eye ( figure(); plot(diff(x)) ) whether the result is satisfactory enough to clearly identify the correct rise time.
Best, Sandro
Sandro makes some good points in his latest comment.
I just want to point out that the loop in the answer is completely unnecessary and the whole lot can be replaced by just:
[peakvalues, where] = max(SurfaceDifferential);
correspondingtime = time(where);
That's a very good and helpful information for me. I think the max value will give a better result for my work. Thank you very much for this Sandro & Guillaume. Much appreciated indeed.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by