The following C program is to implement the pair of lowpass and highpass filters.
any body pls rectifies the error..it shows the error is segmentation fault...
i want to print the value of High and low it show in the program...pls any body tell me...
#include <stdio.h>
#define N 16
#define N1 15
void main()
{
int n;
double buf[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, h[N]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, top, bottom, low, high;
FILE *in, *filt, *out1, *out2;
in = fopen("signal.dat", "r");
filt = fopen("filter.dat", "r");
out1 = fopen("lpf.dat", "w");
out2 = fopen("hpf.dat", "w");
//for (n=0; n<N; n++)
//fscanf (filt, "%lf\n", &h[n]); // Read LPF coefficients
for (n=0; n<=N1; n++)
buf[n] = 0.; // Initialize buffer with zero
//while ( !feof(in) ) // As long as there is data in the file,
{ // the filtering process is continued.
//fscanf (in, "%lf\n", &buf[0]);
top = bottom = 0.;
for (n=0; n<N; n=n+2)
top = top + h[n]*buf[n]; // Even indexed coefficients
for (n=1; n<N; n=n+2)
bottom = bottom + h[n]*buf[n]; // Odd indexed coefficients
low = top + bottom; // Compute LPF output
high = top - bottom; // Compute HPF output
printf("low:%f",low);
printf("HPF:%f",high);
fprintf (out1, "%f\n", low);
fprintf (out2, "%f\n", high);
for (n=N1; n>0; n--)
buf[n] = buf[n-1]; // Update buffer
}
fclose(in);
fclose(filt);
fclose(out1);
fclose(out2);
}
by
jai