can I combine notefreq with various bandpass filters to detect more notes

It seems that the lower notes are detected due possibly to their stronger amplitude. is it possible to patch the input into a bandpass filter then into notefreq to detect notes in higher frequencies? I try and there is no output even when running a 500hz sine wave.

here is my code:

#include <Audio.h>
// Audio setup
AudioInputI2S i2sInput; // Line-in input
AudioFilterStateVariable bandPassFilter1; // Single band-pass filter
AudioAnalyzeNoteFrequency notefreq1; // Single note frequency analyzer
AudioControlSGTL5000 audioShield; // Audio shield for Teensy
AudioConnection patchCord1(i2sInput, 0, bandPassFilter1, 0);
AudioConnection patchCord2(bandPassFilter1, 0, notefreq1, 0);
void setup() {
Serial.begin(115200); // Initialize Serial for debugging
AudioMemory(30); // Allocate memory for audio processing
// Audio Shield setup
audioShield.enable();
audioShield.inputSelect(AUDIO_INPUT_LINEIN); // Use line-in for audio input
audioShield.lineInLevel(15); // Set input gain to maximum
// Configure the band-pass filter
bandPassFilter1.frequency(500); // Focus on 440 Hz for testing
bandPassFilter1.resonance(0.1); // Moderate range for the filter
// Configure the note frequency analyzer
notefreq1.begin(0.10); // Threshold for Yin algorithm
Serial.println("Setup complete. Waiting for signal...");
}
void loop() {
// Analyze notes from the filtered range
if (notefreq1.available()) {
float note1 = notefreq1.read(); // Get detected note frequency
float prob1 = notefreq1.probability(); // Get detection probability
Serial.printf("Note: %3.2f Hz | Probability: %.2f\n", note1, prob1);
} else {
Serial.println("No note detected.");
}
}


thanks for any help or advice.
 
When you post code on this B.Board can you enclose it between code tags using the </> button on the top left of the form.
It maintains the formatting and makes the code much easier to understand.
Code:
#include <Audio.h>
// Audio setup
AudioInputI2S i2sInput; // Line-in input
AudioFilterStateVariable bandPassFilter1; // Single band-pass filter
AudioAnalyzeNoteFrequency notefreq1; // Single note frequency analyzer
AudioControlSGTL5000 audioShield; // Audio shield for Teensy
AudioConnection patchCord1(i2sInput, 0, bandPassFilter1, 0);
AudioConnection patchCord2(bandPassFilter1, 0, notefreq1, 0);
void setup() {
    Serial.begin(115200); // Initialize Serial for debugging
    AudioMemory(30); // Allocate memory for audio processing
    // Audio Shield setup
    audioShield.enable();
    audioShield.inputSelect(AUDIO_INPUT_LINEIN); // Use line-in for audio input
    audioShield.lineInLevel(15); // Set input gain to maximum
    // Configure the band-pass filter
    bandPassFilter1.frequency(500); // Focus on 440 Hz for testing
    bandPassFilter1.resonance(0.1); // Moderate range for the filter
    // Configure the note frequency analyzer
    notefreq1.begin(0.10); // Threshold for Yin algorithm
    Serial.println("Setup complete. Waiting for signal...");
}
void loop() {
    // Analyze notes from the filtered range
    if (notefreq1.available()) {
        float note1 = notefreq1.read(); // Get detected note frequency
        float prob1 = notefreq1.probability(); // Get detection probability
        Serial.printf("Note: %3.2f Hz | Probability: %.2f\n", note1, prob1);
    }
    else {
        Serial.println("No note detected.");
    }
}
 
Try changing patchCord2 so that it outputs to the headphones. You'll then be able to hear whether there's anything coming out of bandPassFilter1.

Pete
 
Back
Top