top of page

소스 코드 제출

공개·회원 50명

arduinofft

#include <arduinoFFT.h>


arduinoFFT FFT = arduinoFFT();


const int micPin = A0;

const uint16_t samples = 128; // FFT 샘플 수

const double samplingFrequency = 5000; // 5kHz 샘플링


double vReal[samples];

double vImag[samples];


void setup() {

Serial.begin(9600);

}


void loop() {

// 1. 마이크 데이터 수집

for (int i = 0; i < samples; i++) {

vReal[i] = analogRead(micPin);

vImag[i] = 0;

delayMicroseconds(100); // 샘플링 속도 제어

}


// 2. FFT 실행

FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);

FFT.Compute(vReal, vImag, samples, FFT_FORWARD);

FFT.ComplexToMagnitude(vReal, vImag, samples);


// 3. 피크 주파수 계산

int peakIndex = FFT.MajorPeak(vReal, samples);

double peakFrequency = (peakIndex * samplingFrequency) / samples;


// 4. 종 구별 (예: 귀뚜라미 A vs B)

if (peakFrequency > 4200 && peakFrequency < 4800) {

Serial.println("귀뚜라미 A 감지!");

}

else if (peakFrequency > 5000 && peakFrequency < 5600) {

Serial.println("귀뚜라미 B 감지!");

}

else {

Serial.print("잡음 또는 다른 소리: ");

Serial.println(peakFrequency);

}


delay(200);

}

2회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page