How can i get frames of a signal using peaks as reference?
2 views (last 30 days)
Show older comments
Perla González Pereyra on 18 Aug 2019
Edited: Perla González Pereyra on 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?
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 on 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:
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:
More Answers (0)
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!