-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
53 lines (42 loc) · 1.1 KB
/
example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "filter.h"
#define DEBUG 0
#define DATA_LEN 2205
#define RUNS 3
#define ORDER 4
int main() {
ChebFilter* filter = create_bw_low_pass_filter(ORDER, (double)2*M_PI*205/44100);
double input[DATA_LEN];
double filtered_signal[RUNS][DATA_LEN];
printf("Opening and reading data file...\n");
FILE *fp = fopen("data/inputs.raw", "r");
if(fp == NULL) {
perror("Unable to open file!");
return(-1);
}
char line[30];
unsigned int i=0;
while(fgets(line, sizeof(line), fp) != NULL) {
sscanf(line, "%lf", &input[i]);
i++;
}
fclose(fp);
printf("Data stored into input[].\n");
for(int j=0; j<RUNS; j++) {
printf("Run #%d:\n", j);
for(int i=0; i<DATA_LEN; i++) {
filtered_signal[j][i] = applyfilter(filter, input[i]);
}
}
printf("Comparing results:\n");
for(int i=0; i<500; i++) {
printf("[bp_filter %i] input: %lf | ", i, input[i]);
for(int j=0; j<RUNS; j++)
printf(" f_out#%d %lf |", j, filtered_signal[j][i]);
printf("\n");
}
free(filter);
return(0);
}