This is a C Program to compute the coefficients of the DFT (Discrete Fourier Transform) directly. The discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values. It can be said to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.

Here is source code of the C Program to Compute DFT Coefficients Directly. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`#include<stdio.h>`

`#include<math.h>`

`#define PI 3.14159265`

struct DFT_Coefficient {

double real, img;

} dft_val;

int main(int argc, char **argv) {

int N = 10;

float a, b, c;

int i;

double function[N];

int k;

double cosine[N];

double sine[N];

printf("Calculation DFT Coefficients\n");

printf("Enter the coefficient of simple linear function:\n");

printf("ax + by = c\n");

scanf("%f", &a);

scanf("%f", &b);

scanf("%f", &c);

for (i = 0; i < N; i++) {

function[i] = (((a * (double) i) + (b * (double) i)) - c);

`//System.out.print( " "+function[i] + " ");`

`}`

printf("Enter the max K value: ");

scanf("%d", &k);

for (i = 0; i < N; i++) {

cosine[i] = cos((2 * i * k * PI) / N);

sine[i] = sin((2 * i * k * PI) / N);

`}`

printf("The coefficients are: ");

for (i = 0; i < N; i++) {

dft_val.real += function[i] * cosine[i];

dft_val.img += function[i] * sine[i];

`}`

printf("( %e )-( %e i )", dft_val.real, dft_val.img);

return 0;

`}`

Output:

$ gcc DFTCoefficient.c $ ./a.out Calculation DFT Coefficients Enter the coefficient of simple linear function: ax + by = c 1 2 3 Enter the max K value: 2 The coefficients are: ( -1.500000e+001 )-( -2.064573e+001 i )

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data Structures and Algorithms.