/*______________________________________________________________________________ MKR2COEF.C Make Radix-2 FIR Coefficients This program takes in the direct form FIR coefficients and converts them into radix-2 FIR coefficients and puts them into a file for R2FIR.ASM. All data will be read and written as floating point. USAGE: mkr2coef ______________________________________________________________________________*/ #include #include #define LINELEN 256 main (argc, argv) int argc; char *argv[]; { FILE *infile, *outfile; char line[LINELEN]; double tmp, x; int len, i; if((argv[1] == NULL) || (argv[2] == NULL)){ printf("USAGE: mkr2coef \ \n"); printf(" This routine converts direct FIR coefficients into \n"); printf(" radix-2 FIR coefficients for R2FIR.ASM. \n"); exit(1); } if((infile = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Error opening %s\n", argv[1]); exit(1); } /* scan for errors, get length of input file */ len=0; while (fgets(line, LINELEN, infile) != NULL) { if (sscanf(line, "%lf", &tmp)!=1) { fprintf(stderr, "Error: flt pnt number not found:\n", argv[1]); fprintf(stderr, " line=%s\n", line); exit(1); } len++; } if ((len % 2) != 0 ) { fprintf(stderr, "Error: # of taps and filter coeff. must be even!\n"); exit(1); } else if (len == 0) { fprintf(stderr, "Error: input file is empty \n"); exit(1); } rewind(infile); /* Open output file */ if((outfile = fopen(argv[2], "w")) == NULL) { fprintf(stderr, "Error opening %s\n", argv[1]); exit(1); } /* Write even coeff to output file */ for (i=0;i