Hi all,
I use an acoustic doppler sensor (PING) to measure distance.
What I want to do is:
-- pass from displacement to velocity
-- make the FFT of the velocity to analyse the components.
At the moment, I can visualize the acquired displacements in Processing. I have also seen that Processing has Minim to do FFT but examples are about sound and audio and not very useful.
Any suggestion how to make these two steps??
This is the processing file to visulaize the displacements
________________________________________
// Graphing sketch
// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return
// Created 20 Apr 2005
// Updated 18 Jan 2008
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
float last_y;
void setup () {
// set the window size:
size(600, 200); //width and heigth
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[2], 115200);
// don't generate a serialEvent() unless you get a newline character:
// myPort.bufferUntil('\n');
// set inital background:
background(255);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');// this is the value taken from Arduino
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
// the plotted value will be reduced by the DC value due to the distance when the target is quiet
// when the target is at 9cm, the sensor measures a distance of 900
// we dcide to subtract a value of 600 because we want to see the simusoidal shape during the target movement
float inByte = float(inString);// data from Arduino minum a constant value of 600
inByte = map(inByte, 0, 100, 0, height); // plotting the data
// draw the line:
stroke(127,34,255);
line(xPos, last_y, xPos, height - inByte);
//point(xPos,inByte);
last_y = height - inByte;
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(255);
}
else {
// increment the horizontal position:
xPos++;
}
}
}
__________________________
I use an acoustic doppler sensor (PING) to measure distance.
What I want to do is:
-- pass from displacement to velocity
-- make the FFT of the velocity to analyse the components.
At the moment, I can visualize the acquired displacements in Processing. I have also seen that Processing has Minim to do FFT but examples are about sound and audio and not very useful.
Any suggestion how to make these two steps??
This is the processing file to visulaize the displacements
________________________________________
// Graphing sketch
// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return
// Created 20 Apr 2005
// Updated 18 Jan 2008
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
float last_y;
void setup () {
// set the window size:
size(600, 200); //width and heigth
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[2], 115200);
// don't generate a serialEvent() unless you get a newline character:
// myPort.bufferUntil('\n');
// set inital background:
background(255);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');// this is the value taken from Arduino
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
// the plotted value will be reduced by the DC value due to the distance when the target is quiet
// when the target is at 9cm, the sensor measures a distance of 900
// we dcide to subtract a value of 600 because we want to see the simusoidal shape during the target movement
float inByte = float(inString);// data from Arduino minum a constant value of 600
inByte = map(inByte, 0, 100, 0, height); // plotting the data
// draw the line:
stroke(127,34,255);
line(xPos, last_y, xPos, height - inByte);
//point(xPos,inByte);
last_y = height - inByte;
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(255);
}
else {
// increment the horizontal position:
xPos++;
}
}
}
__________________________