Amplitude detection in time series data
18 views (last 30 days)
Show older comments
hayder al-omairi
on 17 Sep 2021
Commented: Star Strider
on 19 Sep 2021
I have a time seriese of data recorded from gyroscope I need to detect the specific time of the large Amplitud change ? I can detected manualy but I want automatic detection
note you can see the attachment
0 Comments
Accepted Answer
Star Strider
on 18 Sep 2021
Edited: Star Strider
on 18 Sep 2021
EDIT — (18 Sep 2021 at 13:56)
Another option that occurred to me is to use the envelope function first, and then use findchangepts and ischange on the envelope results, instead of the original signal.
.
1 Comment
Star Strider
on 19 Sep 2021
Part of this was relatively straightforward because the Signal Processing Toolbox has functions that are useful for these sorts of problems. The first peak was not at all straightforward.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/743034/export.csv', 'VariableNamingRule','preserve')
Magnitude = vecnorm(T1{:,2:4},2,2);
MagEnv = envelope(Magnitude, 11, 'peak');
[pw,firstx,lastx] = pulsewidth(MagEnv);
figure
plot(T1.Time, Magnitude)
hold on
plot(T1.Time, MagEnv, '-r')
plot(T1.Time(round(firstx)), MagEnv(round(firstx)), '>g', 'MarkerFaceColor','g')
plot(T1.Time(round(lastx)), MagEnv(round(lastx)), '<r', 'MarkerFaceColor','r')
x = T1.Time;
y = MagEnv - median(MagEnv);
[ymx,idx] = findpeaks(y, 'MinPeakDistance',100, 'NPeaks',1)
% x(idx)
hafmax = ymx*0.1;
for k = 1:numel(hafmax)
idxrng1 = find(y(1:idx(k))<hafmax(k), 1, 'last');
idxrng2 = find(y(idx(k):numel(x))<hafmax(k),1,'first')+idx(k);
xm(k,1) = interp1(y(idxrng1+(-3:3)), x(idxrng1+(-3:3)), hafmax(k));
xm(k,2) = interp1(y(idxrng2+(-3:3)), x(idxrng2+(-3:3)), hafmax(k));
end
plot(xm(1), hafmax+median(MagEnv), '>g', 'MarkerFaceColor','g')
plot(xm(2), hafmax+median(MagEnv), '<r', 'MarkerFaceColor','r')
hold off
grid
The blue line is the magnitude signal, the red line is the envelope, the green markers are the beginning of the pulses and the red markers are the ends of the pulses.
The last four peaks can easily be identified with the pulsewidth function. The first peak is difficult to identify because of the offset, and cannot be used with it, so I went with some legacy code that I use for these sorts of problems. The round values of the ‘firstx’ and ‘lastx’ vectors (they must be integers to be used as indices) identify the indices of the respective parts of the identified ‘pulses’. The ‘xm’ values are the actual times, not the indices.
Experiment to get the results you want.
.
More Answers (1)
Image Analyst
on 18 Sep 2021
Edited: Image Analyst
on 18 Sep 2021
You could probably use stdfilt() or movstd(). Try different window widths and plot the output.
Or try thresholding and labeling. Search for questions on finding words or silence in audio waveforms - there has been a lot of questions regarding that. It's a similar kind of thing.
Attach the data in a .mat or .txt or .csv file if you need more help.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!