How do you section data that has peaks and troughs
4 次查看(过去 30 天)
显示 更早的评论
I have 3 plots X Y Z respectively.
Is there anyway to divide each section for its own magnitude e.g. (at X axis of the top figure 30-60 is walking and 60-80 is running).
i have this right now to separate them but the issue is that the trough of "Run" overlaps "Walk" and so on
actRUN = Yvector(Yvector>15);
actWALKUP = Yvector(Yvector<15);
actWALK = actWALKUP(actWALKUP>5.5);
actRESTUP = Yvector(Yvector<5.5);
actREST = actRESTUP(actRESTUP>0);
actRun = numel(actRUN)
actWalk = numel(actWALK)
actRest = numel(actREST)
pieACT = [actRun actWalk actRest];
Any help would be apreciated since I'm still learning :) ?
6 个评论
Image Analyst
2019-6-16
编辑:Image Analyst
2019-6-16
Star, You're right - and the z was missing. Try the .mat file now. There are lots of ways to solve this. Looking forward to your creative solution.
采纳的回答
Image Analyst
2019-6-16
This seems to work:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in data and plot it.
str = importdata('test2.csv');
t = str.data(:, 1);
x = str.data(:, 1);
y = str.data(:, 2);
z = str.data(:, 3);
% Evaluate y signal.
signal = z;
subplot(2, 1, 1);
plot(t, signal, 'b-');
grid on;
title('Original Signal + Envelope', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
drawnow;
% Find the envelope by taking a moving max operation, imdilate.
windowWidth = 1501; % Or whateve5 spans a few small peaks.
topEnvelope = imdilate(signal, true(windowWidth, 1)); % Or use movmax()
% Find the bottom of the envelope by taking a moving min operation, imerode.
bottomEnvelope = imerode(signal, true(windowWidth, 1)); % Or use movmin()
% Plot it.
hold on;
plot(t, topEnvelope, 'r-', 'LineWidth', 2);
plot(t, bottomEnvelope, 'r-', 'LineWidth', 2);
legend('Data', 'Envelope');
% Save the x axis length so we can apply it to the edit plot
% so they are displayed on the same time frame
% So we can see how it got shorter.
xl = xlim();
% Find the quiet parts.
% Find where upper and lower envelopes are not close together.
envelopeWidth = topEnvelope - bottomEnvelope;
quietParts = envelopeWidth < 1.5; % Or whatever value you want.
subplot(2, 1, 2);
plot(t, quietParts, 'b-', 'LineWidth', 2);
title('Walking or Running? Walking Parts at 1, Running parts at 0', 'FontSize', fontSize);
grid on;
% Make it plot over the same time range as the original
xlim(xl);
% Now do the same for the other signals.
2 个评论
Image Analyst
2019-6-16
You'd need to do it all at once like this:
walking = envelopeWidth > 1.5 & envelopeWidth < 5;
更多回答(1 个)
Image Analyst
2019-6-16
Try a search on silence detection. For example you'll find this link: my answer for one post
The thresholding I used there won't work with your z because it seems to be flat at a level of 10 instead of zero like x and y so you'll have to detect the flat parts, perhaps by using histogram() or movstd().
You should attach your data if you want more help.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Signal Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!