Effacer les filtres
Effacer les filtres

How can I (for a digital signal) estimate the interval between steps of amplitude 1?

1 vue (au cours des 30 derniers jours)
I have a footswitch signal that when is active it gives 1 and when is deactivated delivers 0 sampled every 1 ms; I want to estimate how long is the interval between each step (from the instant when the switch is activated). Considering that only the steps with a duration longer than 5 ms are acceptables. The size of the interval is recorded at the corresponding column of a "vector". For that purpose I´ve developed the code:
for ii=1 : length(vector)
for jj=step : length(footswitch) %Go around the vector of the signal footswitch
while footswitch(jj)==1
if jj < length(footswitch)-4
if footswitch(jj)==footswitch(jj+1)==footswitch(jj+2)==footswitch(jj+3)==footswitch(jj+4)==1
k=jj;
if footswitch(k)==1
steps=k+1;
end
end
end
end
end
for aa=steps : length(footswitch)
while footswitch(jj)==0
p=aa;
if footswitch(p)==0
stepss=p+1;
end
end
end
intervalo=stepss;
vector(ii)=intervalo;
end
Can anyone tell me what is wrong with the code? I've tested it and it gives me a wrong estimation for the first interval and then it just go worse!

Réponse acceptée

W. Owen Brimijoin
W. Owen Brimijoin le 12 Mai 2014
The code you've included doesn't work because we don't know what the variable 'step' is defined as. You might have more luck first using 'diff' to find the time points when your signal goes from 0 to 1. Formally speaking, this is when the first derivative is equal to +1
idx = find(diff(footswitch)==1);
Then you can measure how far apart these indices are (again with 'diff') and use this to get rid of instances that are too close together in time (i.e., that have a first derivative less than or equal to 5 ms).
idx(find(diff(idx)<=5)+1) = [];
This may work better for you and has the benefit of being easier to follow than nested 'if' and 'while' loops.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by