Can't get FFT to work #1856
-
/**
* @file streams-analog-serial.ino
* @author Phil Schatzmann
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/streams-adc-serial/README.md
* @copyright GPLv3
* #TODO retest is outstanding
*/
#include "Arduino.h"
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioRealFFT.h"
AnalogAudioStream in;
AudioInfo info(20000, 1, 16); // sample rate, channel count, bits per sample
AudioRealFFT fft;
StreamCopy copier(fft, in);
AudioFFTResult results[5];
void fftResult(AudioFFTBase &_fft){
_fft.resultArray(results);
for (int i = 0; i < 5; i++) {
Serial.printf("%.2f\t", results[i].frequency);
}
Serial.println();
}
// Arduino Setup
void setup(void) {
// create test signal
tone(14, 10000);
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// reads from GPIO34
auto cfgRx = in.defaultConfig(RX_MODE);
// cfgRx.start_pin = A1; // optinally define pin
// cfgRx.is_auto_center_read = true;
cfgRx.copyFrom(info);
// open output
auto fftCfg = fft.defaultConfig();
fftCfg.copyFrom(info);
fftCfg.window_function = new BufferedWindow(new Hamming());
fftCfg.length = 8192;
fftCfg.callback = &fftResult;
in.begin(cfgRx);
fft.begin(fftCfg);
}
// Arduino loop - copy data
void loop() {
copier.copy(); //
} This is my whole code, things I've tried are swapping out the FFT implementation, tweaking the generated frequency values but no such luck, I've put a jumper from GPIO14 to GPIO34, I can tell that the ADC is reading something since adc-plot works fine and if I connect the GPIO34 to 5v or rub my finger across the pin it also does something |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I don't think you can use this to analyse a pwm signal! I also suggest that you check for the magnitude and filter out the values where the magnitude is too low As a proper test setup I suggest to use an analog microphone and analye some sine tones |
Beta Was this translation helpful? Give feedback.
-
Alright, I'll try with a function generator from my uni's lab and implement the filtering and report back, I think that ought to work hopefully I'll tone down the frequency, it was just to see if I could get any kind of response at all :p |
Beta Was this translation helpful? Give feedback.
I don't think you can use this to analyse a pwm signal!
I also suggest that you check for the magnitude and filter out the values where the magnitude is too low
And the third issue is that your sampling rate is at the edge for measuring such a high frequency
As a proper test setup I suggest to use an analog microphone and analye some sine tones