Skip to content

Instantly share code, notes, and snippets.

@lenidh
Last active September 1, 2015 21:30
Show Gist options
  • Save lenidh/a01b22313e484f169671 to your computer and use it in GitHub Desktop.
Save lenidh/a01b22313e484f169671 to your computer and use it in GitHub Desktop.
DFT matrix generator (gcc -std=c11 -lm dftmgen.c)
#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");
}
}
Copy link

ghost commented Jul 6, 2015

Line 13 should read cos(2*M_PI/n) - sin(2*M_PI/n)*I, as per the trigonometric identity for e^(-ix). Otherwise, thanks for the snippet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment