Go Down

Topic: Help with signal conditioning (Read 4 times) previous topic - next topic

robtillaart

Quote
So far, it's the most reliable signal of sensor activation I found.

Does it solve your problem now? Otherwise you might need the second derivative too.

Missing in the graph is the square wave, derived from the first derivative. Would make the picture complete.

Maybe smoothing the original signal with a moving average is better than smoothing the derivative (should become smoother automatically).
seen this class - http://arduino.cc/playground/Main/RunningAverage - ?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

dhenry

Quote
I wonder if somebody can point me to a software algorithm or an hardware solution to obtain nice square waves (sharp attack, sustain and, what's missing here, a sharp release).


Fundamentally, there is no good solution.

Alternatively, you can introduce some derivative gain, similar to a PID controller, for this.


Thot

#7
Nov 30, 2012, 04:52 pm Last Edit: Nov 30, 2012, 06:26 pm by Thot Reason: 1
Rob,

>>> Does it solve your problem now?

I have to try in practice in my application see if the result is acceptable.
In a "perfect" wind controller, I should be able to detect a gradual decrescendo, that is the player blowing softer and softer to make the sound fade away gradually but I don't know how I would differentiate that from the slow decay that I see when I stop blowing altogether.

>>> Otherwise you might need the second derivative too.

By second derivative you mean something like:

Code: [Select]
newderivative = oldvalue - newvalue ;
secondderivative = oldderivative - newderivative ;
oldderivative = newderivative ; // Remembers the previous one


>>> Missing in the graph is the square wave, derived from the first derivative. Would make the picture complete.

Sorry, I did not include it because it does not show very well, But I am attaching it now. I am also attaching the actual Excel in case you are interested (the 8 periods moving average was calculated in the spreadsheeti itself).

>>> Maybe smoothing the original signal with a moving average is better than smoothing the derivative (should become smoother automatically).

I did not think about that because the actual signal seems clean enough but maybe a 2 or 4 period moving average of the signal will yield a clean derivative as well and be faster to show a true change

>>> seen this class - http://arduino.cc/playground/Main/RunningAverage - ?

No, I haven't. It does look very useful. :)

My approach is very similar to yours in:
Code: [Select]
long runningAverage(int M)
which avoids the need for floating math.

with the difference that I use two distinct routines, one for initializing the array during setup() and one to update the actual running average from loop().
That has the advantage of eliminating
Code: [Select]
 if (count < LMSIZE) count++;

so that the division is always by 16 (in my case) which could be replaced by a rightward 4 bit shift (though if I understand correctly, the compiler is smart enough to make the replacement).
Also, is:
Code: [Select]
 index = index % LMSIZE;


More efficient than:
Code: [Select]
index++ ;
if (index >= LMSIZE) index = 0 ; // If LMSIZE is 16 index cannot be more than 15



I can post the code for my little functions  if of interest (and if you'd like to comment on it)

Thanks again



There are three kind of people in the world: Those who can count, and those who can't

robtillaart

Code: [Select]
newderivative = oldvalue - newvalue ;
secondderivative = oldderivative - newderivative ;
oldderivative = newderivative ; // Remembers the previous one

Yes that should work.


Quote
Also, is:
Code: [Select]
index = index % LMSIZE;
More efficient than:
Code: [Select]
index++ ;
if (index >= LMSIZE) index = 0 ; // If LMSIZE is 16 index cannot be more than 15


No, shorter source code does not always mean shorter exe or faster runtime.
The modulo is a division which is one of the most expensive basic math operations.

Yes, please post the code, you want to share, I'll comment (maybe others too ;)


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart


In the image I see quite some HIGH LOW fluctuations, e.g between [2.2 , 3.6]  smoothing the source signal should really help here.

You can make the square wave higher of course by writing 400 iso 100
Code: [Select]

  // SQUARE OUTPUT (% as example)
  if (derivative > 0) Serial.println(400);
  else Serial.println(0);

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up