How can i get frames of a signal using peaks as reference?

조회 수: 1(최근 30일)
I created some data to simulate a signal, then i calculate the mean and std of this signal and kept only with is up to a define treshold, then i fin the peaks in this new data, now i want to take the first peak detected and the 500ms after, then repeat this proceding with a new peak (not included in the last window) and save this frames in some array.
Anyone knows how can i abord this problem?
This is my code
numberofdata = 1000000;
for i = 1:numberofdata;
datos = [randn(1,4000)] >0.5;
signal(i) = sum(datos); %this is my artificial data
Noisefree=signal(Noisefree); %just the values up

채택된 답변

Sourav Bairagya
Sourav Bairagya 2019년 8월 21일
findpeaks function returns the values of the peaks as well as their locations. Hence, you can store both information in two arrays as follows:
[pks, locs]=findpeaks(Noisefree)
Now, pks(1) and locs(1) will give the value and location of the first peak respectively.
Using this information, you can define the first 500ms time frame which starts from the location of the first peak and can extract the necessary information from your signal Noisefree and save those in some array for further processing.
Here, I am assuming the signal data is spaced at an interval of 1ms. You should change according to the original spacing.
For extracting next frames starting from other peaks which were not included in previous window, you can follow this logic written in this code snippet:
endfrm = locs(1)+499; %End point of 1st frame
start = locs(1)+500; %Probable Starting point of 2nd frame
for j = 2:numel(locs) %Loop will run until last peak location turns up
if(locs(j)>endfrm) %Checking whether this peak is already in the previous window or not
endfrm=locs(j)+499; %If new peak is found, then compute endpoint of the new frame
if(endfrm>numel(Noisefree)) %If end-point exceeds the size of the signal, then limit it to the end index of the signal
arr=Noisefree(locs(j):y); %Extract the desired frame and save
%%Do your required operations on arr
Thus, you can extract and save frames from the signal using peaks as per your preferences.
Here numel function is used to compute the total number of elements in locs.
For more information about “findpeaks” follow this link:
  댓글 수: 3
Perla González Pereyra
Perla González Pereyra 2019년 8월 22일
Thank you very much, I was missing one line in the first code ^^ '
P.S. I really appreciate the time and the detailed explanation. It helped me a lot.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by