resample_spline_filter_interp.c

This program is example of the impulse response and magnitude calculation for the Farrow filter interpolator on the basis of piecewise cubic splines.

Result filter impulse response and magnitude is saved to files:

dat/resample_spline_filter_time.txt - the Farrow filter interpolator impulse response.

dat/resample_spline_filter_freq.txt - the Farrow filter magnitude.

Farrow filter impulse response \(h(n)\) and magnitude \(\left| H\left( \operatorname{e}^{j \cdot \omega}\right)\right|^2\), can be plotted as its showed on the follow figure:

resample_spline_ex_filter_interp.png

Red curve - Farrow filter on the basis of spline interpolation.
Blue curve - Farrow filter on the basis of Lagrange interpolation.

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "dspl.h"
#define P 10
#define Q 1
#define K 512
#define N 5
int main()
{
HINSTANCE hDSPL; /* dspl handle */
double s[N] = {0.0, 0.0, 1.0, 0.0, 0.0};
double *t=NULL; /* time */
double *h=NULL; /* Filter impulse response */
double w[K]; /* Normalized Angular frequency */
double HR[K]; /* Filter frequency response real part */
double HI[K]; /* Filter frequency response image part */
double H[K]; /* Filter magnitude */
int k, nh;
/* Load dspl.dll */
hDSPL = dspl_load();
if(!hDSPL)
{
printf("dspl.dll loading ERROR!\n");
return 0;
}
dspl_resample_spline(s, N, P, Q, 0, &h, &nh);
t = (double*) malloc(nh*sizeof(double));
dspl_linspace(0, nh, nh, DSPL_PERIODIC, t);
dspl_writetxt(t,h,nh,"dat/resample_spline_filter_time.txt");
dspl_linspace(0, M_PI, K, DSPL_PERIODIC, w);
dspl_freqz(h, NULL, nh-1, w, K, HR, HI);
for(k = 0; k < K; k++)
H[k] = 10.0*log10((HR[k]*HR[k] + HI[k]*HI[k]));
dspl_writetxt(w,H,K,"dat/resample_spline_filter_freq.txt");
/* clear dspl handle */
FreeLibrary(hDSPL);
free(h);
free(t);
return 0;
}

Select spelling error with your mouse and press Система Orphus