resample_spline_ex_frac_delay.c Example of using Farrow filter on the basis of spline interpolation to compensate the signal fractional delay.The pickup signal $s(n),$ $n = 0 \ldots 7,$ contains 8 samples as it is shown in the figure below. This program recalculates the pickup signal $s(n)$ into the signal $y(k),$ $k = 0 \ldots 7,$ which is delayed concerning $s(n)$ by the value $x_0 = 0.25$ of the sampling period. The resampling process is read out in the table: ---------------------------------------------------------------------------------------------------------- | k xk n delta | s(n-3) s(n-2) s(n-1) s(n) | a0 a1 a2 a3 | y(k) | ---------------------------------------------------------------------------------------------------------- | 0 -0.25 1 0.25 | 0.0 0.0 1.0 2.0 | 1.0000 1.0000 -0.5000 -0.5000 | 0.7266 | | 1 0.75 2 0.25 | 0.0 1.0 2.0 2.0 | 2.0000 0.5000 -1.0000 -0.5000 | 1.8203 | | 2 1.75 3 0.25 | 1.0 2.0 2.0 1.0 | 2.0000 -0.5000 -0.5000 0.0000 | 2.0938 | | 3 2.75 4 0.25 | 2.0 2.0 1.0 -0.5 | 1.0000 -1.2500 0.0000 0.2500 | 1.3086 | | 4 3.75 5 0.25 | 2.0 1.0 -0.5 -1.0 | -0.5000 -1.0000 1.2500 0.7500 | -0.1836 | | 5 4.75 6 0.25 | 1.0 -0.5 -1.0 -2.0 | -1.0000 -0.7500 -1.0000 -0.7500 | -0.8633 | | 6 5.75 7 0.25 | -0.5 -1.0 -2.0 -0.5 | -2.0000 0.2500 2.7500 1.5000 | -1.9141 | | 7 6.75 8 0.25 | -1.0 -2.0 -0.5 0.0 | -0.5000 1.0000 -2.2500 -1.7500 | -0.8633 | ----------------------------------------------------------------------------------------------------------#include #include #include #include "dspl.h"#define P 1#define Q 1#define N 8 #define X0 0.25int main(){ HINSTANCE hDSPL; /* dspl handle */ /* input signal vector s = [1 2 2 1 -0.5 -1 -2 -0.5] */ double s[N] = {1.0, 2.0, 2.0, 1.0, -0.5, -1.0, -2.0, -0.5}; /* vector z keeps s and 3 additional zeros z = [0 0 1 2 2 1 -0.5 -1 -2 -0.5 0] zeros are necessary for n-3 to be a nonzero. */ double z[N+3]; double y[N]; /*output signal delayed on X0 fractional delay */ double x; /* x_k value */ double delta; /* delta_k value */ double a[4]; /* Polynomial coeff vector */ int k, n; /* Load dspl.dll */ hDSPL = dspl_load(); if(!hDSPL) { printf("dspl.dll loading ERROR!\n"); return 0; } /* z = [0 0 1 2 2 1 -0.5 -1 -2 -0.5 0] */ memset(z, 0, (N+3) * sizeof(double)); memcpy(z+2, s, N*sizeof(double)); /* table header print */ printf("\n\n -----------------------------------------------------"); printf("-----------------------------------------------------\n"); printf(" | k xk n delta | s(n-3) s(n-2) s(n-1) s(n) |"); printf(" a0 a1 a2 a3 | y(k) |\n"); printf(" -----------------------------------------------------"); printf("-----------------------------------------------------\n"); for(k = 0; k < N; k++) { x = (double)k * Q/P - X0; n = floor(x)+2; n+=2; delta = - floor(x) - 1.0 + x; /* spline coefficients calculation */ a[0] = z[n-1]; a[1] = 0.5*(z[n] - z[n-2]); a[3] = 2.0*(z[n-2] - z[n-1]) + a[1] + 0.5*(z[n-1] - z[n-3]); a[2] = z[n-2] - z[n-1] +a[3] + a[1]; dspl_polyval(a,3,&delta, 1, y+k); printf(" | %.1d %6.2f %.1d %6.2f |", k, x, n-2, -delta); printf(" %6.1f %6.1f %6.1f %6.1f |", z[n-3], z[n-2], z[n-1], z[n]); printf(" %8.4f %8.4f %8.4f %8.4f |", a[0], a[1], a[2], a[3]); printf(" %8.4f |\n", y[k]); } printf(" -----------------------------------------------------"); printf("-----------------------------------------------------\n\n"); /* clear dspl handle */ FreeLibrary(hDSPL); return 0;} Generated on Sat Mar 11 2017 12:37:51 for DSPL - Digital signal processing library by   1.8.13