How can I extracting a signal pulse from a data
6 views (last 30 days)
Show older comments
I am basic user of in such coding, I Will be grateful for the help. I have a data file (measured signal) that contains few pulses. I want to extract the first pulse (which is also the highest pulse) from this measured signal and save it as another file for further use. The example is shown in the attachment.I have 50 data files ((measured signal).
I want to extract all the first pulses from these 50 measured signal. There is not very hard requirement for the number of samples extracted related to this pulse, may be start to end (rising zero to falling zero etc) or any thing like this.
1 Comment
dpb
on 22 Sep 2018
Do you have Signal Processing TB? If so, findpeaks will be quite useful here...let us know before we invest time elsewhere.
Accepted Answer
dpb
on 23 Sep 2018
Edited: dpb
on 24 Sep 2018
"extract the first pulse (which is also the highest pulse)"
Presuming you can be assured of the assumption, the first is the max, then it's pretty simple...
[pk,ipk]=max(s); % largest peak, location
ilo=find(s(1:ipk)<pk/2,1,'last'); % lower half-max location
ihi=find(s(ipk:end)<pk/2,1,'first')+ipk; % upper half-max location
pkS=s(ilo:ihi);
ADDENDUM
With the second pdf that looks like baseline-crossing is the desired result,
load('Signal.mat');
[pk,ipk]=max(s); % largest peak, location
BL=0; % set baseline level
ilo=find(s(1:ipk)<=BL,1,'last'); % lower boundary location
ihi=find(s(ipk:end)<=BL,1,'first')+ipk-1; % upper boundary location
pkS=s(ilo:ihi);
See what are results--
>> [ilo,ihi]
ans =
613 682
>> s([ilo ihi]).'
ans =
-8.9407e-12 -0.0004
>>
This is within one element of your location, you can modify the test somewhat by looking for within some eps of BL to get nearest to BL or even interpolate for fractional location or whatever it is thought to be most suitable result.
10 Comments
dpb
on 24 Sep 2018
Edited: dpb
on 25 Sep 2018
There's a "+ipk-1" missing on the location for "ihi"; find is counting from the peak location plus one so the absolute location is from that base point.
You'll have to decide about a thresholding level; as noted in the comments with IA, I just illustrated the search mechanism using FWHM as an example.
If you want more of the peak than that (the pdf is nebulous as to a real definition), you'll have to use a baseline estimate or someother level.
Again, being able to set other parameters in the selection besides a fixed threshold is why I asked about SP Toolbox and findpeaks initially; this is a very simple-minded searching algorithm.
More Answers (1)
Image Analyst
on 22 Sep 2018
This should do it
mask = signal > 2e-3; % Threshold the signal to find regions higher than 2e-3.
% If you get more than one region, use the code below to get only the largest region, otherwise skip it.
mask = bwareafilt(mask, 1);
maskedSignal = signal(mask);
4 Comments
See Also
Categories
Find more on AI for Signals 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!