0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-26 19:23:51 +01:00

Update iir.c

This commit is contained in:
Kuba
2025-08-08 22:49:40 +02:00
committed by GitHub
parent 3d9b7cdf6c
commit 2da62b42fd

View File

@@ -16,17 +16,26 @@ inline float apply_preemphasis(ResistorCapacitor *filter, float sample) {
}
void tilt_init(TiltCorrectionFilter* filter, float alpha) {
filter->alpha = alpha; // 0.95 to 0.99 typically
filter->x_prev = 0.0f;
filter->y_prev = 0.0f;
// Leaky integrator for DC estimation: dc[n] = alpha*dc[n-1] + (1-alpha)*x[n]
// Tilt correction: y[n] = x[n] - dc[n]
if (correction_strength >= 1.0f) {
correction_strength = 0.99999f;
}
if (correction_strength < 0.0f) {
correction_strength = 0.0f;
}
filter->alpha = alpha; // Leaky integrator coefficient
filter->dc_estimate = 0.0f; // Running DC estimate
}
float tilt(TiltCorrectionFilter* filter, float input) {
// High-pass: y[n] = α*y[n-1] + (x[n] - x[n-1])
float output = filter->alpha * filter->y_prev + (input - filter->x_prev);
float tilt_correct(TiltCorrectionFilter* filter, float input) {
// Update DC estimate using leaky integrator
filter->dc_estimate = filter->alpha * filter->dc_estimate + (1.0f - filter->alpha) * input;
filter->x_prev = input;
filter->y_prev = output;
// Remove estimated DC component
float output = input - filter->dc_estimate;
return output;
}