ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MicrophoneFourierBase.h
Go to the documentation of this file.
1/**
2 * @file MicrophoneFourierBase.h
3 * @brief Provides a base class for FFT-based microphone signal processing.
4 *
5 * This file defines the MicrophoneFourierBase class, offering foundational functionality
6 * for performing Fast Fourier Transform (FFT) on microphone input signals. It includes
7 * methods for retrieving FFT results and managing microphone signal data.
8 *
9 * @date 22/12/2024
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include <Arduino.h> // Include for Arduino compatibility.
16#include "../../../../Utils/Filter/DerivativeFilter.h" // Include for derivative filtering.
17#include "../../../../Utils/Filter/FFTFilter.h" // Include for FFT-based filtering.
18#include "../../../../Utils/Time/TimeStep.h" // Include for time management.
19#include "../../../../Utils/Signals/FFT.h" // Include for FFT processing.
20
21/**
22 * @class MicrophoneFourierBase
23 * @brief Base class for FFT-based microphone signal processing.
24 *
25 * The MicrophoneFourierBase class provides foundational support for microphone signal processing,
26 * including FFT transformations, signal normalization, and filtering. Derived classes can extend
27 * its functionality for specific applications.
28 */
30protected:
31 static const uint16_t FFTSize = 256; ///< Size of the FFT (number of samples).
32 static const uint16_t OutputBins = 128; ///< Number of output bins from FFT processing.
33 static uint16_t sampleRate; ///< Sampling rate in Hz.
34 static uint8_t pin; ///< Pin number for microphone input.
35 static float minDB; ///< Minimum decibel value for normalization.
36 static float maxDB; ///< Maximum decibel value for normalization.
37 static float threshold; ///< Threshold value for processing.
38 static float currentValue; ///< Current magnitude of the microphone signal.
39 static bool isInitialized; ///< Flag indicating if the system is initialized.
40
41 static DerivativeFilter peakFilterRate; ///< Filter for peak rate detection.
42
43 static float inputSamp[FFTSize * 2]; ///< Raw input samples for FFT.
44 static float inputStorage[FFTSize]; ///< Storage for processed input samples.
45 static float outputMagn[FFTSize]; ///< Magnitude output from FFT.
46 static float outputData[OutputBins]; ///< Processed FFT data for output bins.
47 static float outputDataFilt[OutputBins]; ///< Filtered FFT data for output bins.
48 static FFTFilter fftFilters[OutputBins]; ///< Array of FFT filters for post-processing.
49
50 static FFT<FFTSize> fft; ///< FFT processor instance.
51
52public:
53 /**
54 * @brief Calculates the average magnitude of the specified FFT bins.
55 *
56 * @param binL The lower bound of the bin range (inclusive).
57 * @param binH The upper bound of the bin range (inclusive).
58 * @return The average magnitude within the specified range.
59 */
60 static float AverageMagnitude(uint16_t binL, uint16_t binH);
61
62 /**
63 * @brief Checks if the microphone system is initialized.
64 *
65 * @return True if initialized, false otherwise.
66 */
67 static bool IsInitialized();
68
69 /**
70 * @brief Retrieves the current sampling rate.
71 *
72 * @return The sampling rate in Hz.
73 */
74 static float GetSampleRate();
75
76 /**
77 * @brief Retrieves the raw input samples.
78 *
79 * @return Pointer to the array of raw input samples.
80 */
81 static float* GetSamples();
82
83 /**
84 * @brief Retrieves the FFT output data.
85 *
86 * @return Pointer to the array of FFT output data.
87 */
88 static float* GetFourier();
89
90 /**
91 * @brief Retrieves the filtered FFT output data.
92 *
93 * @return Pointer to the array of filtered FFT output data.
94 */
95 static float* GetFourierFiltered();
96
97 /**
98 * @brief Retrieves the current signal magnitude.
99 *
100 * @return The current magnitude value.
101 */
102 static float GetCurrentMagnitude();
103};
Calculates the derivative (rate of change) of input values with filtering for stability.
Processes and normalizes FFT data.
Definition FFTFilter.h:26
A templated class for performing Fast Fourier Transform (FFT) operations.
Definition FFT.h:20
Base class for FFT-based microphone signal processing.
static bool isInitialized
Flag indicating if the system is initialized.
static float inputSamp[FFTSize *2]
Raw input samples for FFT.
static const uint16_t FFTSize
Size of the FFT (number of samples).
static FFT< FFTSize > fft
FFT processor instance.
static float GetCurrentMagnitude()
Retrieves the current signal magnitude.
static FFTFilter fftFilters[OutputBins]
Array of FFT filters for post-processing.
static float threshold
Threshold value for processing.
static float outputData[OutputBins]
Processed FFT data for output bins.
static const uint16_t OutputBins
Number of output bins from FFT processing.
static bool IsInitialized()
Checks if the microphone system is initialized.
static DerivativeFilter peakFilterRate
Filter for peak rate detection.
static float outputMagn[FFTSize]
Magnitude output from FFT.
static float maxDB
Maximum decibel value for normalization.
static float currentValue
Current magnitude of the microphone signal.
static float GetSampleRate()
Retrieves the current sampling rate.
static float inputStorage[FFTSize]
Storage for processed input samples.
static uint8_t pin
Pin number for microphone input.
static float outputDataFilt[OutputBins]
Filtered FFT data for output bins.
static float AverageMagnitude(uint16_t binL, uint16_t binH)
Calculates the average magnitude of the specified FFT bins.
static float * GetSamples()
Retrieves the raw input samples.
static uint16_t sampleRate
Sampling rate in Hz.
static float * GetFourierFiltered()
Retrieves the filtered FFT output data.
static float minDB
Minimum decibel value for normalization.
static float * GetFourier()
Retrieves the FFT output data.