473,412 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

probably a stupid question: MatLab equivalent of "diff" ?

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.

thanks,
Stef Mientki
Dec 29 '06 #1
1 5825
Stef Mientki 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.
Using numpy (or predecessors), you can do this easily with slicing:

a[1:] - a[:-1]

Slicing shares data, so the slices above don't create new arrays, but
new views into the old array, so it avoids that overhead.

For Python lists you'd have to use a list comprehension or some such
thing like that. For example:

[ x-y for (x,y) in zip(a[1:],a[:-1]) ]

Or, to avoid creating two new arrays, use iterators:

import itertools
[ x-y for (x,y) in
itertools.izip(itertools.islice(a,0,-1),itertools.islice(a,1)) ]
Carl

Dec 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
6
by: GoogleGroups | last post by:
"Residual" is the diff between returns of two funds. I've got a form. The form will have two and only two records on it: one for Fund#1 and the other for Fund#2. Each record contains...
3
by: Pascal | last post by:
please let me explain the situation. we're a software developement company, with about 30 people coding in C under MS Visual C++ Studio. We have a source file system (Telelogic CM Synergy,...
1
by: ad | last post by:
Hi, What is the difference between (string)dr and dr.ToString();
9
by: SQL | last post by:
This is a little more of a logic question. But I'm doing this in VB.NET, so I figured this is the right place to ask: I need to figure out the difference between a range that a user will...
12
by: Robbie Hatley | last post by:
I'm getting a bizarre error with this code: ... case WM_COMMAND: { switch (LOWORD(wParam)) // switch (control ID) { ... case IDC_RAIN_ENABLE_SIMPLE: {
40
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost...
12
by: erikcw | last post by:
Hi all, I have a collection of ordered numerical data in a list. The numbers when plotted on a line chart make a low-high-low-high-high-low (random) pattern. I need an algorithm to extract the...
25
by: Peng Yu | last post by:
Hi, It is possible to change the length of "\t" to a number other than 8. std::cout << "\t"; Thanks, Peng
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.