How can i get frames of a signal using peaks as reference?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Perla González Pereyra
am 18 Aug. 2019
Bearbeitet: Perla González Pereyra
am 22 Aug. 2019
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?
Thanks
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
end
threshold=mean(signal)+std(signal)*2.5;
Noisefree=find(signal>umbral);
Noisefree=signal(Noisefree); %just the values up
burst=findpeaks(Noisefree)
0 Kommentare
Akzeptierte Antwort
Sourav Bairagya
am 21 Aug. 2019
“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.
arr=Noisefree(locs(1):locs(1)+499);
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
endfrm=numel(Noisefree);
end
arr=Noisefree(locs(j):y); %Extract the desired frame and save
end
%%Do your required operations on arr
end
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 Kommentare
Sourav Bairagya
am 22 Aug. 2019
You can first initialize a matrix M with the first frame extracted.
M = arr1; %arr1 is the first frame starting from 1st peak
Then, inside the for loop, you can append the new frames as rows to it.
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
endfrm=numel(Noisefree);
end
arr=Noisefree(locs(j):y); %Extract the desired frame and save
M = [M; arr];
end
%%Do your required operations on arr
end
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!