summaryrefslogtreecommitdiff
path: root/NaiveFFT/main.c
blob: 6372c79c084d2fd4fac0e83c6f2f9ff28382d66c (plain) (blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
//  main.c
//  NaiveFFT
//
//  Created by Jacky Jack on 10/08/2021.
//

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <complex.h>
#include <time.h>
#include <stdint.h>

#if __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif

#include "fft.h"

//test data array
#define DATA_SIZE (8)
//double data_i[DATA_SIZE] = {0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f};
//double data_q[DATA_SIZE] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
double data_i[DATA_SIZE] = {1.0f,1.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
double data_q[DATA_SIZE] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};



int main(int argc, const char * argv[]) {
#if __EMSCRIPTEN__
    printf("Wasm NaiveFFT module loaded\n");
#else 
    int i;
    
    // insert code here...
    printf("Hello FFT World!\n");
    
    for (i=0;i<DATA_SIZE;i++) {
        printf("%.2f ",data_i[i]);
    }
    printf("\n");
    for (i=0;i<DATA_SIZE;i++) {
        printf("%.2f ",data_q[i]);
    }
    printf("\n");
    ffti_shuffle_1(data_i, data_q, DATA_SIZE);
    fft_1(data_i, data_q, DATA_SIZE, 0);
    
    //run dft by default
    //dft(data_i, data_q, DATA_SIZE,0);
    
    printf("after FFT\n");
    
    for (i=0;i<DATA_SIZE;i++) {
        printf("%.2f ",data_i[i]);
    }
    printf("\n");
    for (i=0;i<DATA_SIZE;i++) {
        printf("%.2f ",data_q[i]);
    }
    printf("\n");
    
    //big buffer test
    {
        time_t timer;
        char buffer[32];
        struct tm *tm_info;
        
        timer = time(NULL);
        tm_info = localtime(&timer);
        
        strftime(buffer, 32, "%H:%M:%S", tm_info);
        puts(buffer);
        
    }
    
    //test big big fft
    {
        double *d_i=malloc(sizeof(double)*4*8192+16);
        double *d_q=malloc(sizeof(double)*4*8192+16);
        for (i=0;i<4*8192;i++) {
            d_i[i] = sin(i*1.0/128);
            d_q[i] = 0.0f;
        }
        
        dft(d_i, d_q, 4*8192,0);
        free(d_i); d_i = NULL;
        free(d_q); d_q = NULL;
    }
    
    {
        time_t timer;
        char buffer[32];
        struct tm *tm_info;
        
        timer = time(NULL);
        tm_info = localtime(&timer);
        
        strftime(buffer, 32, "%H:%M:%S", tm_info);
        puts(buffer);
    }
#endif
    return 0;
}