如何仅转换现有Arduino FFT源的输入信号源

时间:2017-09-05 11:21:16

标签: fft

我的问题是一个。 我想通过Arduino对不稳定的输入电压进行FFT。 如何从现有的Arduino FFT源转换?

我是Arduino首发。 请给我一个详细的答案。

/*
fft_adc_serial.pde
guest openmusiclabs.com 7.7.14
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb.
*/

#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft

#include <FFT.h> // include the library

void setup() {
Serial.begin(115200); // use the serial port
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
}

void loop() {
while(1) { // reduces jitter
cli();  // UDRE interrupt slows this way down on arduino1.0
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fft_window(); // window the data for better frequency respons
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_log(); // take the output of the fft
sei();
Serial.println("start"); // header send 
for (byte i = 0 ; i < FFT_N ; i+=2) { 
Serial.write(fft_input[i]);   // send out the real part
Serial.write(fft_input[i+1]); // send out the imaginary part

 }
}
}

0 个答案:

没有答案