I think you missed the point of the code I gave. The key line was the "x = x.astype(int8)" that converted the information to 8 bit amplitude resolution (in the C programming language, it was converted to the signed character type); this simulates the data coming from one of the instruments. The subtraction to get the derivative results in severe roundoff error. In fact, if you print out the difference array, the only numbers in the array are 0 and ±1. Scaling the difference array by any factor is useless because the information is gone.
You won't see the problem if you do it with the typical 8-byte IEEE floating point arithmetic like you did in the spreadsheet. But you can probably simulate the problem in your spreadsheet by multiplying by 128 and then taking the integer value -- then do the differencing.
But, as I said, for edge and glitch detection, that's probably not important, as it's the high frequency stuff of interest. But it is something I'll have to warn the unwary user about.
I'm struggling to get you DSP-knowledgeable folks to understand the programming constraints I'm up against here.
That array x in the code I gave above is a numpy array containing 1 to 2 million floating point values. In reality, it's a chunk of memory allocated in a C library and given array semantics by numpy. But I don't have the luxury of iterating on the points in that array in C -- I can do it, but it's in a scripting language (python), which is hundreds of times slower than C. If I use a chunk of python code like
to mess with individual points, I've slowed the application down a lot -- and it will be unacceptable to users. Thus, I have to use the built-in functions of numpy to do the point-by-point processing and I'm constrained by what numpy offers.
When I get back to working on this problem, I'll take a look at the suggestion by Tesla23, as it meshes with your suggestions and might be a way of getting at the interesting stuff. In fact, numpy does have primitives to do comparisons and choosing things from an array in one fell swoop, so this might be a fruitful approach.
The other significant constraint I have is that I can't throw unlimited effort at the problem, as I'm doing the work as a consultant and the customer has to be satisfied that the work is necessary. Right now, we have other issues that need to be attacked first. I recently changed to a sampled display (the waveform shown on the screen is a sample of the waveform in memory); the older version plotted every point. Thus, the old code showed every little wiggle in the waveform, but the new code doesn't. I'm anticipating that the engineers at the company I'm doing the work for will find that not displaying the glitches (i.e., interesting stuff) like before is problematic for their customers and will want some change in the code to do so. Hence this question, as I don't really have a good idea on how to attack the problem. I thought some of the AAC readers would have some good ideas, so that's why I asked.
You won't see the problem if you do it with the typical 8-byte IEEE floating point arithmetic like you did in the spreadsheet. But you can probably simulate the problem in your spreadsheet by multiplying by 128 and then taking the integer value -- then do the differencing.
But, as I said, for edge and glitch detection, that's probably not important, as it's the high frequency stuff of interest. But it is something I'll have to warn the unwary user about.
I'm struggling to get you DSP-knowledgeable folks to understand the programming constraints I'm up against here.
Rich (BB code):
for i in xrange(len(x)):
process(x)
When I get back to working on this problem, I'll take a look at the suggestion by Tesla23, as it meshes with your suggestions and might be a way of getting at the interesting stuff. In fact, numpy does have primitives to do comparisons and choosing things from an array in one fell swoop, so this might be a fruitful approach.
The other significant constraint I have is that I can't throw unlimited effort at the problem, as I'm doing the work as a consultant and the customer has to be satisfied that the work is necessary. Right now, we have other issues that need to be attacked first. I recently changed to a sampled display (the waveform shown on the screen is a sample of the waveform in memory); the older version plotted every point. Thus, the old code showed every little wiggle in the waveform, but the new code doesn't. I'm anticipating that the engineers at the company I'm doing the work for will find that not displaying the glitches (i.e., interesting stuff) like before is problematic for their customers and will want some change in the code to do so. Hence this question, as I don't really have a good idea on how to attack the problem. I thought some of the AAC readers would have some good ideas, so that's why I asked.