2016-10-11 6 views
0

현재 PRO 트랭킷이 오디오 입력의 64 포인트 FFT를 수행하고 RGB 매트릭스를 제어하는 ​​arduino에 빈의 출력/크기를 전송하는 프로젝트에서 작업 중입니다.FFT 구현 및 출력 사용

나는 내 fft 코드를 http://wiki.openmusiclabs.com/wiki/ArduinoFFT에서 파생했다. 정확히 어떻게 출력 (fft_log_out)을 사용하고 데이터를 전송하는지 알아낼 수는 있지만 내 코드는 작동에 가깝다.

/* 
fft_adc.pde 
guest openmusiclabs.com 8.18.12 
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. there is a pure data patch for 
visualizing the data. 
*/ 

#define LOG_OUT 1 // use the log output function 
#define FFT_N 64 // set to 64 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 
int freq_array [32]; 
} 

void loop() { 
while(1) { // reduces jitter 
cli(); // UDRE interrupt slows this way down on arduino1.0 
for (int i = 0 ; i < 124 ; i += 2) { // save 64 samples 
    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_input[i] = k; // put real data into even bins 
    fft_input[i+1] = 0; // set odd bins to 0 
} 
fft_window(); // window the data for better frequency response 
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 


// Amplitude Ranges if else tree 

for(int j=0; j<32; j++){  
if (fft_log_out[j] < 2000 && fft_log_out[j] > 180){freq_array[j] = 16;} 
else{ if (fft_log_out[j] <= 180 && fft_log_out[j] > 160){freq_array[j] = 15;} 
else{ if (fft_log_out[j] <= 160 && fft_log_out[j] > 130){freq_array[j] = 14;} 
else{ if (fft_log_out[j] <= 130 && fft_log_out[j] > 110){freq_array[j] = 13;} 
else{ if (fft_log_out[j] <= 110 && fft_log_out[j] > 90){freq_array[j] = 12;} 
else{ if (fft_log_out[j] <= 90 && fft_log_out[j] > 70){freq_array[j] = 11;} 
else{ if (fft_log_out[j] <= 70 && fft_log_out[j] > 60){freq_array[j] = 10;} 
else{ if (fft_log_out[j] <= 60 && fft_log_out[j] > 50){freq_array[j] = 9;} 
else{ if (fft_log_out[j] <= 50 && fft_log_out[j] > 40){freq_array[j] = 8;} 
else{ if (fft_log_out[j] <= 40 && fft_log_out[j] > 30){freq_array[j] = 7;} 
else{ if (fft_log_out[j] <= 30 && fft_log_out[j] > 20){freq_array[j] = 6;} 
else{ if (fft_log_out[j] <= 20 && fft_log_out[j] > 15){freq_array[j] = 5;} 
else{ if (fft_log_out[j] <= 15 && fft_log_out[j] > 11){freq_array[j] = 4;} 
else{ if (fft_log_out[j] <= 11 && fft_log_out[j] > 8){freq_array[j] = 3;} 
else{ if (fft_log_out[j] <= 8 && fft_log_out[j] > 5){freq_array[j] = 2;} 
else{ if (fft_log_out[j] <= 5 && fft_log_out[j] > 2){freq_array[j] = 1;} 
else{ if (fft_log_out[j] <= 2 && fft_log_out[j] > 0){freq_array[j] = 0;} 
}}}}}}}}}}}}}}}}} 

sei(); 


String sta = "M"; 
String aa = str(freq_array[0]); //ERROR: 'freq_array' was not declared in this scope 
String bb = str(freq_array[1]); 
String cc = str(freq_array[2]); 
String dd = str(freq_array[3]); 
String ee = str(freq_array[4]); 
String ff = str(freq_array[5]); 
String gg = str(freq_array[6]); 
String hh = str(freq_array[7]); 
String ii = str(freq_array[8]); 
String jj = str(freq_array[9]); 
String kk = str(freq_array[10]); 
String ll = str(freq_array[11]); 
String mm = str(freq_array[12]); 
String nn = str(freq_array[13]); 
String oo = str(freq_array[14]); 
String pp = str(freq_array[15]); 
String qq = str(freq_array[16]); 
String rr = str(freq_array[17]); 
String ss = str(freq_array[18]); 
String tt = str(freq_array[19]); 
String uu = str(freq_array[20]); 
String vv = str(freq_array[21]); 
String ww = str(freq_array[22]); 
String xx = str(freq_array[23]); 
String yy = str(freq_array[24]); 
String zz = str(freq_array[25]); 
String aaa = str(freq_array[26]); 
String bbb = str(freq_array[27]); 
String ccc = str(freq_array[28]); 
String ddd = str(freq_array[28]); 
String eee = str(freq_array[30]); 
String fff = str(freq_array[31]); 

String com = ","; 
String newl = "\n"; 

String send1 = sta + aa + com + bb + com + cc + com + dd + com + ee + com + ff + com + gg + com + hh + com + ii + com + jj + com + kk + com + ll + com + mm + com + nn + com + oo + com + pp + com + qq + com + rr + com + ss + com + tt + com + uu + com + vv + com + ww + com + xx + com + yy + com + zz + com + aaa + com + bbb + com + ccc + com + ddd + com + eee + com + fff + newl; 
Serial.write(send1); 


} 

} 
} 

답변

0

당신은을 받고 :(, 내가 주 동안이 작업 한이에 대한 몇 가지 도움을받을 좋은 것 'freq_array이'이 범위 에서 선언되지 않은 : 라인 73에서 나는이 오류 오류 freq_arraysetup() 기능 범위의 지역 변수로 선언, 따라서 당신이 그것을 사용하려고이 범위 외부에서 액세스 할 수 없습니다 때문에

ERROR: 'freq_array' was not declared in this scope 

.

당신은 단순히 필요이 오류를 해결하려면 십 선언을 이동하여 파일 범위에서 LARE freq_arraysetup() 함수 본문 외부에있을 수 있습니다 :

int freq_array[32]; 
void setup() { ... 
+0

좋은 포인트. 그 오류를 수정했지만 지금은 'str'은 C로 작성하고 C++로 작성하지 않았기 때문에 선언되지 않았습니다. 나는 전에 str을 사용한 적이 없다. C에서 어떻게 구현합니까? – FLITSCHI

+0

실제로'str'은 C가 아닙니다.'char aa [BUF_SIZE]; sprintf (aa, "% .0f", freq_array [idx])는 각 변수에 적절한 버퍼 크기를 갖습니다. – SleuthEye