All pastes #918664 Raw Edit

Unnamed

public text v1 · immutable
#918664 ·published 2008-02-26 08:24 UTC
rendered paste body
//---------------------------------------------------------------------------

#include <stdio.h>
#include <conio.h>


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

#define SIZE 20
#define SAMPLE 2000


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];
	}
}

void filter_short(short *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];
	}
}

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
                        };

        short b[SIZE] = {
      332,    531,    321,   -566,  -1750,  -2191,   -820,   2522,   6620,
     9445,   9445,   6620,   2522,   -820,  -2191,  -1750,   -566,    321,
      531,    332
        };
        
        double sample[SAMPLE];
        double out[SAMPLE];
        FILE *fOut;

        for (i=0; i<SAMPLE; i++)
                sample[i] = i;

        //filter(a, sample, out);
        filter_short(b, sample, out);


        fOut = fopen("out.txt", "wb");
        if (fOut == NULL){
		printf("Can't open output file!\nPress any key to continue...");
		while(!kbhit());
		return 1;
	}

        for (i=0; i<SAMPLE; i++)
        {
                double fo = out[i];
		fwrite(&fo,sizeof(double),1,fOut);
                printf("%d: %f\n", i, out[i]);
        }

        fclose(fOut);

        while (!kbhit());


        return 0;
}


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