The sampling frequency of the ATmega328 is very limited. Even if you reduce the prescaler factor, reading the signal of an ultrasonic receiver is unsatisfactory. (As you can see, for this purpose, I still use the old IDE as it offers to display 500 samples rather than the new one with only 50 samples.)
In this graph, each reading is plotted five times, otherwise you would not see anything. The first idea was to join the corners by straight lines.
Now it looks slightly better, but still not nice.
There is not much math to do this:
int y2 = receive[i]; // new value
/* perform quadratic interpolation: */
float a = (y2 - 2 * y1 + y0) * 0.5;
float b = (y2 - y0) * 0.5;
float c = y1;
for (int j = 0; j < N1; j++) {
float t = (float) j / N1;
float y = a * sq(t) + b * t + c;
Serial.print(send[i] * 500);
Serial.print(" ");
Serial.println(y);
The values y0, y1, and y2 are the three recent readings. The US transmitter is driven by the same sketch, its values are kept in the sens[]-array.
Comments
Please log in or sign up to comment.