vendredi 27 mars 2015

Circular Buffer in C



I need to modify a program to use a circular buffer for the input data window This is the program:



#include <stdio.h>
#include <math.h>
#include "p2.h"
void slide(double y[], double in)
{
int i;
for(i=0; i<N-1; i++) y[i] = y[i+1];
y[N-1] = in;
}
double filter(double y[] ,double x)
{
int i;
double out=0;
for(i=0;i<N;i++)
{
out = y[i]*c[i] + out;
}
return out;
}
int main( void)
{
int s;
double d, y[N]={0};
while( 1 )
{
s = scanf("%lf",&d);
if( s != 1)
break;
{
slide(y,d);
d = filter(y,d);
printf( "%g\n", d);
}
}
return 0;
}


This is a bonus question for a homework assignment and i need the extra points, any help would be incredible.




Aucun commentaire:

Enregistrer un commentaire