All pastes #918648 Raw Edit

Stuff

public text v1 · immutable
#918648 ·published 2008-02-26 08:01 UTC
rendered paste body
//---------------------------------------------------------------------------
#include <malloc.h>
#include <stdio.h>

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#define SIZE 20
#define SAMPLE 5
void filter(double *pCoeffs, double *pIn, double *pOut);

int main(int argc, char* argv[])
{
        int i;
        double a[SIZE] = {
    0.01012540679169,  0.01619011662008, 0.009786728378426, -0.01728521320085,
   -0.05341272232682, -0.06686228261234, -0.02501874309413,  0.07695974701189,
     0.2020233515395,   0.2882283854912,   0.2882283854912,   0.2020233515395,
    0.07695974701189, -0.02501874309413, -0.06686228261234, -0.05341272232682,
   -0.01728521320085, 0.009786728378426,  0.01619011662008,  0.01012540679169
                        };
        double sample[SAMPLE] = {
                        2, 2, 2, 2, 2
                        };
        double out[SAMPLE];

        filter(a, sample, out);

        for (i=0; i<SAMPLE; i++)
        {
                printf("%f", out[i]);
        }


        return 0;
}

void filter(double *pCoeffs, double *pIn, double *pOut)
{
	int i,j;
        double Delay[SIZE];

	for (i=0; i<SIZE; i++)
		Delay[i]=0;

        pOut[0] = 0;
	for (i=0; i<SAMPLE; i++){
		for (j=(SIZE-1); j>0; j--)
			Delay[j] = Delay[j-1];
		Delay[0] = pIn[i];
		for (j=0; j<SIZE; j++)
			pOut[i] = pOut[i] + pCoeffs[j]*Delay[j];
	}
}

//---------------------------------------------------------------------------