0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-27 11:33:54 +01:00

this isn't better

This commit is contained in:
2025-01-01 02:07:45 +01:00
parent e77a10f33c
commit 6fecb974d5
2 changed files with 30 additions and 20 deletions

View File

@@ -1,24 +1,8 @@
#include "hilbert.h"
static float generate_coefficient(int i, int nzeros) {
if (i == nzeros/2) return 0.0f;
float n = i - nzeros/2;
// Basic Hilbert transform coefficient
float h = (i == nzeros/2) ? 0.0f : (2.0f/(PI * n));
// Apply Blackman window for better stopband attenuation
float w = 0.42f - 0.5f * cosf(2.0f * PI * i / nzeros) +
0.08f * cosf(4.0f * PI * i / nzeros);
return h * w;
}
void init_hilbert(HilbertTransformer *hilbert) {
hilbert->delay = calloc(D_SIZE, sizeof(float));
hilbert->dptr = 0;
for(int i = 0; i < NZEROS; i++) {
hilbert->coeffs[i] = generate_coefficient(i, NZEROS);
}
}
void apply_hilbert(HilbertTransformer *hilbert, float sample, float *output_0deg, float *output_90deg) {
@@ -27,7 +11,7 @@ void apply_hilbert(HilbertTransformer *hilbert, float sample, float *output_0deg
hilbert->delay[hilbert->dptr] = sample;
hilb = 0.0f;
for(int i = 0; i < NZEROS/2; i++) {
hilb += (hilbert->coeffs[i] * hilbert->delay[(hilbert->dptr - i*2) & (D_SIZE - 1)]);
hilb += (xcoeffs[i] * hilbert->delay[(hilbert->dptr - i*2) & (D_SIZE - 1)]);
}
*output_0deg = hilbert->delay[(hilbert->dptr - 99) & (D_SIZE - 1)];