How do you section data that has peaks and troughs

3 vues (au cours des 30 derniers jours)
Axiemeon Manaois
Axiemeon Manaois le 16 Juin 2019
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 commentaires
Star Strider
Star Strider le 16 Juin 2019
@IA —
Thank you. That worked, except that x == t.
Image Analyst
Image Analyst le 16 Juin 2019
Modifié(e) : Image Analyst le 16 Juin 2019
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.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 16 Juin 2019
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.
0000 Screenshot.png
  2 commentaires
Axiemeon Manaois
Axiemeon Manaois le 16 Juin 2019
Modifié(e) : Image Analyst le 16 Juin 2019
I can see the path of your solution,, im wondering if there is anyway to break it up to 3 segments instead cause there are actually 3 parts : running walking and rest
quietParts = envelopeWidth < 1.5; % Or whatever value you want.
I increased this to 25 for only 60-80 at the x axis to be considered as running (also renamed it running), so it became
running = envelopeWidth < 25
and i added a new figure(2)
rest= envelopeWidth < 1.5
plot...
which worked, but i cannot figure out how to isolate just the walking (example of this is at 30-60 and 140-150 at the X axis). i tried
walking = envelopeWidth < 5;
walking = envelopeWidth > 1.5;
but it doesnt seem to work.
thanks for the amazing help
Image Analyst
Image Analyst le 16 Juin 2019
You'd need to do it all at once like this:
walking = envelopeWidth > 1.5 & envelopeWidth < 5;

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 16 Juin 2019
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.

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by