/*
  Test if pcqfilter() and ipcqfilter() are inverses.
*/

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#include "pcqfilt.c"


int
main(void)
{
  /* Daubechies 4 filter coefficients: */
  const float h[4] = {  0.48296291314453416, 0.83651630373780794,
			0.22414386804201339, -0.12940952255126037};
  const float g[4] = { -0.12940952255126037, -0.22414386804201339,
		       0.83651630373780794, -0.48296291314453416};
  const int L=4, N=12;
  float in[12], out[12]={0}, rec[12]={0}, save[12]={0};
  int n;

  for(n=0; n<12; n++)
    save[n]=in[n]=(float)(n*n-12*n+13);	/* test signal */


  printf("   u[%d:%d]:", 0,N-1);
  for(n=0; n<N; n++) printf(" %f", in[n]);
  putchar('\n');

  pcqfilter(out,in,N/2, h,g,L);

  printf("  Fu[%d:%d]:", 0,N-1);
  for(n=0; n<N; n++) printf(" %f", out[n]);
  putchar('\n');

  ipcqfilter(rec,out,N/2, h,g,L);

  printf("F*Fu[%d:%d]:", 0,N-1);
  for(n=0; n<N; n++) printf(" %f", rec[n]);
  putchar('\n');

  printf("diff[%d:%d]:", 0,N-1);
  for(n=0; n<N; n++) printf(" %f", rec[n]-save[n]);
  putchar('\n');
  return 0;
}

