Hi everyone, still having a problem with my timegrapher. The first issue was to implement the fft and I did it with Matlab, and it was ok. On the attached file, you can see the signal (samples[n]) coming from the mic to the Serial plotter. On the Y-axis we have the output in millivolt and the X-axis the samples. Now I want to serial.print a graph with magnitude in dB on the Y-axis and time in second or millisecond on the X-axis. Can someone please tell how to proceed ?
Thanks in advance
#include <SPI.h>
#define SS 5
int16_t* samples;
uint32_t n = 0;
int count = 0;
unsigned long start_time;
unsigned long end_time;
const unsigned long event = 10000;
const uint32_t max_samples=50000;
void setup() {
Serial.begin(115200); /* initialization of serial communication */
SPI.begin(); /* initialization of SPI port */
SPI.setDataMode(SPI_MODE0); /* configuration of SPI communication in mode 0 */
SPI.setClockDivider(SPI_CLOCK_DIV64); /* configuration of clock at 1MHz */
pinMode(SS, OUTPUT);
Serial.println("Start");
samples = (int16_t*)malloc(sizeof(int16_t)*max_samples);
if(samples == NULL){
Serial.print("insufficient memory");
}
else{
Serial.print("malloc ok.");
}
}
void loop() {
start_time = millis();
for (n=0; n<max_samples; n++)
{
samples[n] = Sound();
}
end_time = millis();
Serial.print("Dauer [ms]: ");
Serial.print((end_time-start_time));
Serial.print(" ||| ");
Serial.print("Beats: ");
Serial.print(n);
Serial.println(" ||| ");
for (n = 0; n < max_samples; n++)
{
Serial.print(samples[n]);
//Serial.print(",-32768,32767");
Serial.println();
}
}
int16_t Sound(void) {
digitalWrite(SS, LOW); //activate chip select
int sound = SPI.transfer(0) | (SPI.transfer(0) << 8); //reconstruct 12-bit data
digitalWrite(SS, HIGH); //deactivate chip select
return sound;
}