[SciPy-user] probably a stupid question: MatLab equivalent of "diff" ?
s.mientki at ru.nl
Fri Dec 29 10:37:32 CST 2006
thanks Tom, Otto,Lev,
for the fast respons,
but the problem still exists (btw I'm fairly newbie, for those didn't
discovered that ;-).
- I import SciPy
- I do some calculations to find specific events, and the last
BP_detect = ( dBP_dt > 0 ) & ( IOO > 40000 )
- now this is really great (compared to MatLab), because the resulting
array is a real boolean array,
so it only consists of True and False and presumably only takes 8 bits
per value ???
- now if I run some standard diff formule, I'll detect both the edges,
I expect that is due to the True/False elements of the array,
probably they are internally translated to +1 and -1 ???
- even this gives both edges
BP_peaks = numpy.diff ( BP_detect) > 0
- in the meanwhile I found a algorithm that works, but I find it very ugly
( I process the data in chunks, therefor I use and save the last sample
BP_peak = logical_and( concatenate(( ([BP_peak_prev]),
BP_detect[:-1])), logical_not(BP_detect) )
BP_peak_prev = BP_detect[-1]
Any Ideas ?
Tom Denniston wrote:
> Ignore, mine. Otto's answer is better. I didn't see it.
> On 12/29/06, Tom Denniston <tom.denniston at alum.dartmouth.org> wrote:
>> I may be misunderstanding you but isn't what you want just:
>> If you only want positive differences it's:
>> (arr[1:]-arr[:-1]) > 0
>> or negative:
>> (arr[1:]-arr[:-1]) < 0
>> These should be very fast.
>> On 12/29/06, Stef Mientki <s.mientki at ru.nl> wrote:
>>> Does anyone know the equivalent of the MatLab "diff" function.
>>> The "diff" functions calculates the difference between 2 succeeding
>>> elements of an array.
>>> I need to detect (fast) the falling edge of a binary signal.
>>> There's derivate function in Python diff,
>>> but when you use an binary (true/false) input,
>>> it also detects rising edges.
>>> Probably a stupid question,
>>> but I still have troubles,
>>> digging to huge amount of information about Python.
>>> Stef Mientki
>>> SciPy-user mailing list
>>> SciPy-user at scipy.org
> SciPy-user mailing list
> SciPy-user at scipy.org
More information about the SciPy-user