473,785 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5905
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.islic e(a,0,-1),itertools.is lice(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
10054
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def, serveur.Data_tblTABLEDECODEAUNEVALEUR TDC_AUneValeur where def.TYPEDETABLEDECODES = 4
6
1827
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 FundName and FundReturn. At the bottom of the form, I need to show the diff between Fund#1's return and Fund#2's return.
3
1374
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, basicaly identical to cvs) that handle all the different versions (it's a very huge tree) Of course, we have very often the problem to report some modifications done on a file to many other versions. This job is actually done manualy.
1
1873
by: ad | last post by:
Hi, What is the difference between (string)dr and dr.ToString();
9
1265
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 enter...only they will be entering alphanumeric characters. Like "A" to "E"...I want to return the difference which would be 5 (A being 1 and E being 5). How can I do this?
12
2114
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
3160
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 fcn is a boolean and there are certain places within the inner functions where it may become apparent that the return value is false. In this case I'd like to halt the computation immediately and return false. My current approach is to have...
12
1772
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 "significant" high and low points from this data. Here is some sample data: data =
25
30991
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
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10346
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.