Last active
September 1, 2015 21:30
-
-
Save lenidh/a01b22313e484f169671 to your computer and use it in GitHub Desktop.
DFT matrix generator (gcc -std=c11 -lm dftmgen.c)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <complex.h> | |
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define M_PI 3.1415926535897932384626433832795L | |
int main(int argc, char** argv) { | |
int n = 0; | |
if(argc > 1) n = atoi(argv[1]); | |
for(int i = 0; i < n; i++) { | |
for(int j = 0; j < n; j++) { | |
complex double omega = cos(2*M_PI/n) - sin(2*M_PI/n)*I; | |
omega = cpow(omega, i*j); | |
printf("(%f,%f)", creal(omega), cimag(omega)); | |
} | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 13 should read
cos(2*M_PI/n) - sin(2*M_PI/n)*I
, as per the trigonometric identity fore^(-ix)
. Otherwise, thanks for the snippet!