seperate sample data into sub-vectors

I am currently trying to do a frequency analysis on some sample data from a sensor. Therefore I want to seperate the different sections of the large sample data vector into independent ones. The picture shows the sample data. Each section is a two spiked amplitude with some idling before and after. I figured I could use a threshold to get all the data above set values. But I need some of the iddle before and after that. With the current threshold 5000 samples before the first and after the last data of each amplitude should do.
% determine how many samples there are in total
N=length(SampleData);
% generate sample domain for plot
x=linspace(1,N,N);
PositiveThreshold = 500;
NegativeThreshold = -500;
% get the samples above the threshold
dataIdx = SampleData > PositiveThreshold | SampleData < NegativeThreshold;
SamplePtsAboveThres = x(dataIdx);
How do I get 5000 samples before and after each amplitude and how do I seperate that into independent vecors? Should I use a for loop?
You help is very appreciated!
Edit: I could seperate the vectors by hand but I hoped for something smarter which does that automated.

8 件のコメント

dpb
dpb 2020 年 6 月 20 日
"The picture shows the sample data"
Excepting forgot to attach it ... :)
I'd suggest more robust would be to use findpeaks to locate the peaks of interest -- once you have those locations, then selecting some time before them is pretty-much just computing how many time steps to keep based on sample rate.
If you don't have Signal Processing TB, then is a little more work to locate peaks reliably unless they are quite noise free -- still doable, but there's where seeing the data would help. Of course, attaching an actual data as well file would be even more useful for someone to play with!
Christian
Christian 2020 年 6 月 20 日
Yeah, you're right. I've added the missing plot, plus the sample data. The noise is pretty low in comparison to the data. As a student I do have basically every TB.. :-)
dpb
dpb 2020 年 6 月 20 日
Explore the options available in findpeaks, then. You can do all kinds of stuff...
Christian
Christian 2020 年 6 月 20 日
Okay, thank you. I will try that!
Christian
Christian 2020 年 6 月 23 日
編集済み: Christian 2020 年 6 月 23 日
I did some testing with the findpeaks function and I am able to reliablely detect the two peaks of each amplitude. But I am struggling to think of a solution to determine the width of the whole amplitude. The half-height option is probably the inital point for that but as the amplitudes quite differ in shape it is hard to determine the start and end point. Is it possible to compute these points with the gradient emanating from the half-height point?
[pks,locs, width, prominences] = findpeaks(SampleData, x , 'MinPeakHeight', ...
2000, 'MinPeakDistance', 3000, 'MinPeakProminence', 100, 'Annotate', ...
'extents', 'WidthReference','halfheight');
findpeaks(SampleData, x , 'MinPeakHeight', 2000, 'MinPeakDistance', 3000, ...
'MinPeakProminence', 100, 'Annotate','extents', 'WidthReference','halfheight');
dpb
dpb 2020 年 6 月 23 日
For your flat baseline characteristics, can't you use the returned peak prominence vector to find the baseline value region and then locate the positions to left/right of each peak that are within some tolerance thereof?
I'm not positive what your search criterion is, but from the above figure that would seem pretty reliable general approach. The one tricky point is if look at only point-by-point, there are those few little +/- spikes there that could potentially trigger a start/end point if happened to be right at the base of the real peak.
dpb
dpb 2020 年 6 月 23 日
Another "trick" is to negate the waveform and then use findpeaks again -- excepting now you're finding minima. I've not played much with it to find a flat top region, but wouldn't put it past being able to make that work pretty well for these data with some experimenting.
Christian
Christian 2020 年 6 月 24 日
Alright, thank you again for your suggestions! I will experiment some more on this.

回答 (0 件)

この質問は閉じられています。

製品

リリース

R2020a

質問済み:

2020 年 6 月 20 日

閉鎖済み:

2020 年 8 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by