I'm trying to do thresholding on a signal about 50000 samples long.
I want to get the samples (index) closest to the threshold.
What I've done so far basicaly is
x_above = x>threshold
x_above is a logical vector that looks like:
x_above = [ 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 . . . 0 0 1 1 1 0]
What I want to get is all the indeces at which the signal crosses the
threshold up and then down. That is the index of the first and the last 1 of
each group of 1's. I am testing all the values of x_above in a loop, but it
takes very long to compute. I am looking for help in vectorizing this.
The loop is something like this:
------------------------------------------
LeftBracket =[]; % Start index of each group of 1's
RightBracket = [];% End index of each group of 1's
TZswitch = 0; %This switch indicates if we're in a sequence of 1's or out
for k = 1:length(x_above)
if x_above(k) == 1
if TZswitch==0
% Put current index in LeftBracket and set the switch to ON
LeftBracket = [LeftBracket k];
TZswitch = 1;
end
elseif TZswitch ==1
% Put current index in RightBracket and set the swith to OFF
RightBracket = [RightBracket k];
LZswitch = 0;
end
end
----------------------------------------------------------------------------
-
All help greatly appreciated.
--
The main thing is to keep the main thing the main thing.
H. Beckenridge
-----------------------------------------------------------
N.B. I only check the listed e-mail
from time to time to clean the spam.
-----------------------------------------------------------
1) convert ..010.. double sequence to a STRING
s=sprintf('%s',x_above+'0');
2) now
xup=strfind(s,'01');
xdown=strfind(s,'10');
3) and from here on
us
"Bill Stones" <mail2...@yahoo.com> wrote in message
news:a6ngdm$fqbgg$1...@ID-112827.news.dfncis.de...
xup=strfind(x_above,[char(0) char(1)]);
xdown=strfind(x_above,[char(1) char(0)]);
... just a thought
us
"us" <u...@neurol.unizh.ch> wrote in message
news:3c8f4b84$1...@zinews.unizh.ch...
> why not consider this
> 1) convert ..010.. double sequence to a STRING
> s=sprintf('%s',x_above+'0');
<SNIP>
xup=strfind(x_above,[0 1]);
xdown=strfind(x_above,[1 0]);
us
"us" <u...@neurol.unizh.ch> wrote in message
news:3c8f4c55$1...@zinews.unizh.ch...
Sam
"us" <u...@neurol.unizh.ch> wrote in message
news:3c8f4daa$1...@zinews.unizh.ch...
> x_above is a logical vector that looks like:
>
> x_above = [ 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 . . . 0 0 1 1 1 0]
>
> What I want to get is all the indeces at which the signal crosses the
> threshold up and then down. That is the index of the first and the last 1
Why not just do:
find(diff(x_above))
This will give you a string of crossing locations,
alternately up, then down.
John
--
How about something like (untested):
LeftBracket = find(diff(x_above) == 1);
RightBracket = find(diff(x_above) == -1);
--
Peter Boettcher <boet...@ll.mit.edu>
MIT Lincoln Laboratory
MATLAB FAQ: http://www.mit.edu/~pwb/cssm/
1) it works with DOUBLES (just another trail of bytes)
- and - more importantly
2) it allows to find more complex patterns, eg
strfind(x_above,[0 1 1 1 0])
that often is much faster than any of the <set member> functions.
us
"Sam Boulton" <sbou...@mathworks.co.uk> wrote in message
news:a6nmbm$3ms$1...@sabina.mathworks.co.uk...
"us" <u...@neurol.unizh.ch> wrote in message news:3c8f...@zinews.unizh.ch...
find(diff(x) ~=0)
where x is the vector of 0s and 1s
You may wish to add one to the index depending on
where you want to catch the rising or falling edge
--
The main thing is to keep the main thing the main thing.
H. Beckenridge
-----------------------------------------------------------
N.B. I only check the listed e-mail
from time to time to clean the spam.
-----------------------------------------------------------
"Bill Stones" <mail2...@yahoo.com> wrote in message
news:a6ngdm$fqbgg$1...@ID-112827.news.dfncis.de...