Go Down

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

Thot

Hello All,
  I am not sure if my problem has a hardware or software solution but any help will be appreciated.

I am experimenting with the Modern Devices Wind Sensor:
http://shop.moderndevice.com/products/wind-sensor

in the attempt to make a midi wind controller with Arduino.

The sensor is very responsive and has a nice resolution BUT, a very slow decay time.
In other words, when you stop blowing, the output takes several second to reach baseline.
If I take the output at face value, my instrument would keep playing for several seconds after I stop blowing.

I am attaching a graph I obtained by plotting analog read vs. time.
In the upper graph I gave four quick "pulse" breaths, in the lower one I did a sudden start, steady blow for a few seconds and sudden stop.
As you can see, in either case it takes up to 10-15 seconds to go back to baseline.

The topic has been discussed a few month ago @ modern devices forum but without a real solution, and my fiddling with software (since I am a total newbie when it comes to electronics) didn't carry me very far.

Since I suspect this is hardly a unique problem, 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).

Thank you

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

robtillaart

#1
Nov 29, 2012, 08:12 pm Last Edit: Nov 29, 2012, 08:15 pm by robtillaart Reason: 1
You must determine the first derivative (steepness and direction of the graph) and use that to make your decisions in the code.

That way you do not need to wait until the baseline is reached, you can wait until a certain value is reached.

assuming the signal is analog, give this code a try
Code: [Select]

int oldval = 0;
int newval = 0;

void setup()
{
 Serial.begin(115200);
 Serial.println("Square breathing 0.1");
}

void loop()
{
 newval = analogRead(A0);  // measure the wind
 int derivative = (newval - oldval);  // first derivative of the signal
 oldval = newval;  // remember previous value

 // OUTPUT CAN BE COPIED TO EXCEL
 Serial.print(millis());
 Serial.print(";");
 Serial.print(oldval);
 Serial.print(";");
 Serial.print(newval);
 Serial.print(";");
 Serial.print(derivative);
 Serial.print(";");

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


Please post the graph ...
Rob Tillaart

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

robtillaart

Code: [Select]
if (derivative > 0) Serial.println(100);
  else Serial.println(0);


you can of course also use newval in this comparison to suppress some noise.

Code: [Select]
if (derivative > 0  && newval > 40) Serial.println(100);
  else Serial.println(0);


Multiple analog reads and averaging them also suppresses some noise of the ADC (==analogRead().
I often average 4, 8 or 16 reads as this divides fast.
Rob Tillaart

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

Thot

#3
Nov 29, 2012, 08:33 pm Last Edit: Nov 29, 2012, 11:28 pm by Thot Reason: 1
Thanks for the quick and thorough reply.

I'll test your code and post the results!

I have the results.

The graph did not show well because there are two bands at 0 and 100 but it looks like we are getting something. The 16 values running average of the derivative in particular seems to pick up nicely when the signal is increasing or decreasing or staying relatively steady.

I am attaching the spreadsheet itself so you can take a look.

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

Thot

#4
Nov 30, 2012, 03:39 am Last Edit: Nov 30, 2012, 03:45 am by Thot Reason: 1
This is another test.
The 16 values moving average of the derivative was calculated on the fly by the Arduino.
It appears that it stays 0 when there is no activity, picks up immediately when I blow on the sensor and drops immediately when I stop blowing, remaining negative or 0 for most of the decay.

The interval between the time th signal begins fading and the moving average reaches 0 (at about 3.7 seconds) is 111 ms.

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

Thanks again!

P.S. On the plot I multiplied the value of the moving average by 50 so to be able to superimpose it to the actual signal.

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

Go Up