extract-noise.c from EmStar at Krugle
Show extract-noise.c syntax highlighted
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 32768
#define PRE_FILTER 20
#define PERCENT 0.4
int main(int argc, char **argv)
{
float cols[25];
float data[MAX];
int i,k;
int maxind;
float max = 0;
if (argc != 2) {
fprintf(stderr, "needs col arg 0-3\n");
exit(1);
}
int channel = atoi(argv[1]);
char buf[256];
gets(buf);
while (1) {
int status = scanf("%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n",
&cols[0], &cols[1], &cols[2], &cols[3], &cols[4],
&cols[5], &cols[6], &cols[7], &cols[8], &cols[9],
&cols[10], &cols[11], &cols[12], &cols[13], &cols[14],
&cols[15], &cols[16], &cols[17], &cols[18], &cols[19],
&cols[20], &cols[21], &cols[22], &cols[23], &cols[24]);
if (status != 25) {
break;
}
data[i] = cols[19+channel];
float temp = fabsf(data[i]);
if (max < temp) {
maxind = i;
max = temp;
}
i++;
if (i>=MAX) {
printf("too long!\n");
exit(1);
}
}
fprintf(stderr, "maxind=%d, max=%f..", maxind,max);
max = max * PERCENT;
for (k=0; k<i; k++) {
if (fabsf(data[k]) > max) {
maxind = k;
break;
}
}
fprintf(stderr, " first: maxind=%d, max=%f..\n", maxind,max);
printf("#h c\n");
for (k=0; k<i; k++) {
if (k > maxind-PRE_FILTER && k < maxind+8192) continue;
printf("%f\n", data[k]);
}
return 0;
}
See more files for this project here