
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Program to Compute DFT Coefficients Directly
In discrete Fourier transform (DFT), a finite list is converted of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids. They ordered by their frequencies, that has those same sample values, to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.
Algorithm
Begin Declare three variables which are the coefficient of linear equation and max value Read the variables Define a class with two variables real, img Create a constructor and set real, img to zero Take a variable M and initialize it to some integer Create function[M] For i=0 to M do function[i] = (((a * (double) i) + (b * (double) i)) - c) Declare function sine[M] Declare function cosine[M] for i = 0 to M do cosine[i] = cos((2 * i * k * PI) / M) sine[i] = sin((2 * i * k * PI) / M) for i = 0 to M do dft_value.real += function[i] * cosine[i] dft_value.img += function[i] * sine[i] Print the value End
Example Code
#include<iostream> #include<math.h> using namespace std; #define PI 3.14159265 class DFT_Coeff { public: double real, img; DFT_Coeff() { real = 0.0; img = 0.0; } }; int main(int argc, char **argv) { int M = 10; cout << "Enter the coeff of simple linear function:\n"; cout << "ax + by = c\n"; double a, b, c; cin >> a >> b >> c; double function[M]; for (int i = 0; i < M; i++) { function[i] = (((a * (double) i) + (b * (double) i)) - c); } cout << "Enter the max K value: "; int k; cin >> k; double cosine[M]; double sine[M]; for (int i = 0; i < M; i++) { cosine[i] = cos((2 * i * k * PI) / M); sine[i] = sin((2 * i * k * PI) / M); } DFT_Coeff dft_value; cout << "The coeffs are: "; for (int i = 0; i < M; i++) { dft_value.real += function[i] * cosine[i]; dft_value.img += function[i] * sine[i]; } cout << "(" << dft_value.real << ") - " << "(" << dft_value.img << " i)"; }
Output
Enter the coeff of simple linear function: ax + by = c 4 6 7 Enter the max K value: 4 The coeffs are: (-50) - (-16.246 i)
- Related Articles
- C program to compute geometric progression
- C program to compute linear regression
- C program for Binomial Coefficients table
- C++ Program to Compute Combinations using Factorials
- Program to compute Log n in C
- C Program to Compute Quotient and Remainder?
- Python Program to Compute a Polynomial Equation given that the Coefficients of the Polynomial are stored in a List
- C++ Program to Compute Determinant of a Matrix
- C program to compute the polynomial regression algorithm
- C++ Program to Compute Cross Product of Two Vectors
- C++ Program to compute division upto n decimal places
- 8085 Program to compute LCM
- C++ Program to Compute Combinations using Recurrence Relation for nCr
- C++ Program to Compute Discrete Fourier Transform Using Naive Approach
- C++ Program to Compute the Area of a Triangle Using Determinants

Advertisements