Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions 5_practice.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,47 @@
#include <stdlib.h> // for memory allocation
#include <time.h> // for time calculation
#include <math.h> // for sine and cosine functions

int main() {
// Declare all the variables
int k, n, N;
int u ,k, n, N;
double *x, *yr, *yi;
time_t t;

// Input the number N


printf("Please input a number N = ");
scanf("%d", &N);
// Locate the memory for x, yr, yi;

// Initial setting for x, for example, x[k] = k




x = (double *) malloc(N*sizeof(double));
yr = (double *) malloc(N*sizeof(double));
yi = (double *) malloc(N*sizeof(double));

// Initial setting for x, for example, x[k] = k, k=0..N-1
for(k=0;k<N;++k) {
x[k] = k;
}
t = clock();

// yr[n]+i*yi[n] = sum(exp(-i 2 Pi k n / N)*x[k], k=0..N-1), n=0..N-1







for(n=0;n<N;n++) {
yr[n] = 0.0;
yi[n] = 0.0;
u = 2*M_PI*n/N;
for(k=0;k<N;++k) {
yr[n] += cos(u*k)*x[k];
yi[n] -= sin(u*k)*x[k];
}
}

// output the results
t = clock() - t;
printf("%d ms for discrete Fourier Transform of %d elements\n", t, N);

// free the memory located by x, yr, yi

free(x);
free(yr);
free(yi);


return 100;
}

1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
3. 繼續寫下去 XD
4. 大家來簽到吧
5. 這是一個測試
6. Binchiling! 峰