Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
numerical_methods Namespace Reference

for io operations More...

Functions

std::complex< double > * FastFourierTransform (std::complex< double > *p, uint8_t n)
 FastFourierTransform is a recursive function which returns list of complex numbers. More...
 

Detailed Description

for io operations

Numerical Methods.

for std::map container

for std::vector

for math operations

Numerical methods

for assert for mathematical-related functions for storing points and coefficents for IO operations

Numerical algorithms/methods

for assert for math functions for integer allocation for std::atof for std::function for IO operations

Numerical algorithms/methods

Function Documentation

◆ FastFourierTransform()

std::complex< double > * numerical_methods::FastFourierTransform ( std::complex< double > *  p,
uint8_t  n 
)

FastFourierTransform is a recursive function which returns list of complex numbers.

Parameters
pList of Coefficents in form of complex numbers
nCount of elements in list p
Returns
p if n==1
y if n!=1

Base Case To return

Declaring value of pi

Calculating value of omega

Coefficients of even power

Coefficients of odd power

Assigning values of even Coefficients

Assigning value of odd Coefficients

Recursive Call

Recursive Call

Final value representation list

Updating the first n/2 elements

Updating the last n/2 elements

Deleting dynamic array ye

Deleting dynamic array yo

40 {
41 if (n == 1) {
42 return p; /// Base Case To return
43 }
44
45 double pi = 2 * asin(1.0); /// Declaring value of pi
46
48 cos(2 * pi / n), sin(2 * pi / n)); /// Calculating value of omega
49
50 auto *pe = new std::complex<double>[n / 2]; /// Coefficients of even power
51
52 auto *po = new std::complex<double>[n / 2]; /// Coefficients of odd power
53
54 int k1 = 0, k2 = 0;
55 for (int j = 0; j < n; j++) {
56 if (j % 2 == 0) {
57 pe[k1++] = p[j]; /// Assigning values of even Coefficients
58
59 } else
60 po[k2++] = p[j]; /// Assigning value of odd Coefficients
61 }
62
64 FastFourierTransform(pe, n / 2); /// Recursive Call
65
67 FastFourierTransform(po, n / 2); /// Recursive Call
68
69 auto *y = new std::complex<double>[n]; /// Final value representation list
70
71 k1 = 0, k2 = 0;
72
73 for (int i = 0; i < n / 2; i++) {
74 y[i] =
75 ye[k1] + pow(om, i) * yo[k2]; /// Updating the first n/2 elements
76 y[i + n / 2] =
77 ye[k1] - pow(om, i) * yo[k2]; /// Updating the last n/2 elements
78
79 k1++;
80 k2++;
81 }
82
83 if(n!=2){
84
85 delete[] pe;
86 delete[] po;
87
88 }
89
90 delete[] ye; /// Deleting dynamic array ye
91 delete[] yo; /// Deleting dynamic array yo
92 return y;
93}
std::complex< double > * FastFourierTransform(std::complex< double > *p, uint8_t n)
FastFourierTransform is a recursive function which returns list of complex numbers.
Definition: fast_fourier_transform.cpp:40
T pow(T... args)
Here is the call graph for this function: