안녕하세요 fft 관련 주제로 작업하고 있습니다.
페이지 정보
작성자 김진중 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 작성일16-01-18 16:02 조회1,787회 댓글1건본문
FFT 관련 주제로 프로젝트를 하나 하고 있는데 open music labs에서 관련코드를 빌려 작업을 하고 있습니다.
/*
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
for (int i = 0 ; i < 512 ; i += 2) { // save 256 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
for (int i = 0 ; i < 512 ; i += 2) {
fft_input[i] = (fft_input[i] >> 8);
fft_input[i+1] = -(fft_input[i+1] >> 8);
}
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.print("start");
for (byte i = 0 ; i < FFT_N ; i+=2 ) {
if (! ((i>=20 && i<=40) || (i>=FFT_N-40 && i<=FFT_N-20)))
{
fft_input[i] = 0;
fft_input[i+1] = 0;
}
Serial.println(fft_input[i]); // send out the data
}
}
}
이렇게 해서 매트랩상에서 아두이노의 fft된 데이터들을 불러와 inverse fft를 수행하고 싶은데 matlab 상에서 복원이 되질 않습니다.(원래의 데이터가 복구되지 않음)
조언해주시면 감사하겠습니다.
댓글목록
최고관리자님의 댓글

매트랩으로 FFT 돌린 결과와 아두이노에서 돌린 결과를 한번 비교해보세요. FFT 관련 내용은 저도 잘 몰라서요;;;