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

man github.dev is better than that, but tilt doesn't work

This commit is contained in:
Kuba
2025-08-08 23:04:51 +02:00
committed by GitHub
parent 1ec3ee9466
commit 883d2f86dc
2 changed files with 14 additions and 13 deletions

View File

@@ -15,22 +15,22 @@ inline float apply_preemphasis(ResistorCapacitor *filter, float sample) {
return out; return out;
} }
void tilt_init(TiltCorrectionFilter* filter, float alpha) { void tilt_init(TiltCorrectionFilter* filter, float correction_strength) {
// Allow correction_strength > 1.0 for aggressive correction filter->alpha = 0.9999f;
filter->alpha = 0.9999f; // Fixed time constant for DC tracking filter->gain = correction_strength; // Can be > 1.0
filter->gain = alpha; // Separate gain parameter filter->x_prev = 0.0f;
filter->dc_estimate = 0.0f; filter->y_prev = 0.0f;
} }
float tilt(TiltCorrectionFilter* filter, float input) { float tilt(TiltCorrectionFilter* filter, float input) {
// Track the baseline/DC level // High-pass filter
filter->dc_estimate = filter->alpha * filter->dc_estimate + (1.0f - filter->alpha) * input; float hp_out = filter->alpha * (filter->y_prev + input - filter->x_prev);
// Calculate the deviation from baseline // Apply gain and add back to original
float deviation = input - filter->dc_estimate; float output = input + filter->gain * hp_out;
// Apply correction gain and add back to baseline filter->x_prev = input;
float output = filter->dc_estimate + deviation * filter->gain; filter->y_prev = hp_out;
return output; return output;
} }

View File

@@ -15,7 +15,8 @@ float apply_preemphasis(ResistorCapacitor *filter, float sample);
typedef struct { typedef struct {
float alpha; float alpha;
float dc_estimate; float x_prev;
float y_prev;
float gain; float gain;
} TiltCorrectionFilter; } TiltCorrectionFilter;