Hello,
I'm not an advance player in Arduino game, so would be happy for dumb explanations for my might-be-silly questions.
I am using arduino due.
I would like to retrieve/process/store data from my analog input(microphone) with external program - Matlab. As far as I understood, I need to use serial communication for this.
I also made simple tests to make sure my sampling frequency is high -- with only analogRead function, it says that I get ~250k samples per second, which is high, and more than enough for me. I need just 40kHz for audible sound's manipulations.
But! when I add serial.print, it ruins everything. It slows down to [what??] smth around 2.5kHz.
this is sample code, it's an easy one(and I hope I did it correctly). I'm using hightest possible for serial monitor baud rate - 115200.
the question is, if I increase baud to maximum(someone said it's possible to set 1Mhz), will I get higher sampling frequency? what does it depend on? =//
One more question: how am I supposed to finally enjoy all of Signal Processing MATlab features without losing frequency rate? at least 40kHz...
and one more question(attention, the most stupid one): Am I right, saying that the more functions/math expressions/ processings/lines I add within loop() function, less sampling rate I get?
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(A0, INPUT);
}
long startTime, endTime;
void loop() {
startTime=millis();
// put your main code here, to run repeatedly:
for (int i=0; i<1000; i++){
int senV=analogRead(A0);
//Serial.println(senV);
}
endTime=millis();
long a=1000000/(endTime-startTime);
Serial.print("a=");
Serial.println(a);
}
As far as I understood, I need to use serial communication for this.
Since that is what Matlab understands how to do, yes.
But! when I add serial.print, it ruins everything. It slows down to [what??] smth around 2.5kHz.
Part of that is having to convert the value to a string. You can avoid that part by sending binary data.
if I increase baud to maximum(someone said it's possible to set 1Mhz), will I get higher sampling frequency?
Of course. But, does Matlab work at that speed?
One more question: how am I supposed to finally enjoy all of Signal Processing MATlab features without losing frequency rate? at least 40kHz...
What signal process are you doing?
Am I right, saying that the more functions/math expressions/ processings/lines I add within loop() function, less sampling rate I get?
Yes. Some functions/processing have more impact than others. Incrementing a variable is fast. Writing to an SD card is not. You can't just count statements to get an estimate of speed.