#include "driver/adc.h"
#include < math.h >
#define SAMPLE_RATE 8000 // Sampling Frequency (8kHz)
#define TARGET_FREQ 1000.0 // Frequency to detect
#define N 128 // Number of samples per Goertzel block
#define THRESHOLD 1000 // Threshold for tone detection
float coeff, Q1, Q2, sine, cosine;
int samples[N];
float magnitude;
void setup() {
Serial.begin(115200);
adc1_config_width(ADC_WIDTH_BIT_12); // Configure ADC width
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11); // Configure ADC channel
float k = 0.5 + ((N * TARGET_FREQ) / SAMPLE_RATE);
float omega = (2.0 * M_PI * k) / N;
sine = sin(omega);
cosine = cos(omega);
coeff = 2.0 * cosine;
}
void loop() {
Q1 = 0;
Q2 = 0;
// Sample the input signal
for (int i = 0; i < N; i++) {
samples[i] = adc1_get_raw(ADC1_CHANNEL_0); // Read ADC value