File: fftw.c

package info (click to toggle)
haskell-statistics 0.16.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: haskell: 6,819; ansic: 35; python: 33; makefile: 9
file content (46 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (5)
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
/* Generate some test cases using fftw3  */
#include <stdlib.h>
#include <stdio.h>
#include <fftw3.h>

void dump_vector(int n, double* vec) {
    for(int i = 0; i < n; i++)
        printf("%20.15f ", vec[i]);
    printf("\n");
}

void dct(int flag, int n) {
    double* in  = malloc( n * sizeof(double));
    double* out = malloc( n * sizeof(double));
    //
    fftw_plan plan = fftw_plan_r2r_1d(n, in, out, flag, FFTW_ESTIMATE);
    for( int k = 0; k < n; k++) {
        // Init input vector
        for( int i = 0; i < n; i++)
            in[i] = 0;
        in[k] = 1;
        // Perform DFT
        fftw_execute(plan);
        // Print results
        dump_vector(n, in );
        dump_vector(n, out);
        printf("\n");
    }
    //
    free(in);
    free(out);
    fftw_destroy_plan(plan);
}

int main(void)
{
    printf("DCT II (the DCT)\n");
    dct( FFTW_REDFT10, 2);
    dct( FFTW_REDFT10, 4);
    
    printf("DCT III (Inverse DCT)\n");
    dct( FFTW_REDFT01, 2);
    dct( FFTW_REDFT01, 4);
    
    return 0;    
}