-1

I am working on pedestrian step detection (acceleration). I want to calculate statistical features from my filtered signal. I have already calculated some and now I want to calculate gradient. My data is of 1x37205 double. I calculated features using for loop with moving window size=2samples and 50% overlap of previous window. Below I am attaching the code I tried to calculate the gradient. I am not sure if it is the right way to calculate or not? In addition, I am also unable to understand that what is the purpose to use gradient, how it can be useful for step detection and how to work with gradient? Could some one guide me or provide any code help in matlab?

%%Here M is mean and V is variance i already calculated from filtered data
G = zeros(length(window:length(M)), 2);
for i = window:length(M)
temp = gradient(M(i+1-window:i),V(i+1-window:i));
G(i, 1) = temp(2, 1); % "c1"
G(i, 2) = temp(2, 1); % "c2"
end
buddemat
  • 4,552
  • 14
  • 29
  • 49

1 Answers1

0

One of the best features of Matlab is its documentation. If you are unfamiliar on how to get specific function documentation, enter the following in the command line:

doc functionName

Alternatively, for 'brief' documentation that displays in the command line, you can enter:

help functionName

Also see the documentation link here.

Your question is worded poorly, so I will summarize what I understand and answer accordingly:

  • You have a step detection data (1*37205) double, let us call it stepSignal
  • stepSignal is position data
  • You want your window to be 2 steps with 50% overlap. This is the default behavior for the gradient function.

You do not need a "for" loop to achieve your goal. According to the documentation, "gradient" can take one input.

See the code below, and if need be add clarifications to the original question.

%% Assume that stepSignal is already imported into the workspace
velocity = gradient(stepSignal);

One last note, when you give "gradient" two inputs, it automatically assumes the second input is a uniform spacing value.

  • Thanks for your nice explanation,i understand well, just one last thing if i want to use a large window size, like 10 or any with same 50% overlap to previous window so still i do not need to use for loop and just give my signal as input to calculate it, as you said this is the default behaviour for the gradient function. So there will be no effect either increase the size or not? @ibrahimabusharkh – muhamamd hammad malik Feb 01 '21 at 12:39
  • sorry to bother you again. as you said previously that no need to use forloop as gradient do it. but what i want is to calculate gradient(central difference) with any window size like 20 or 50 samples with 50% overlap. i tried following but without overlap. how i can add that over lap. Grad =gradient(Data_filtered(1:window:end),window) @ibrahimabusharkh – muhamamd hammad malik Feb 16 '21 at 11:36
  • Hi. Could you please give me a sample data set and the sample output you would like to get out? – ibrahim abusharkh Feb 17 '21 at 12:48
  • Also please upvote the answer if you think it is useful. – ibrahim abusharkh Feb 17 '21 at 12:50