mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
clang-format and clang-tidy fixes for 405d21a5
This commit is contained in:
parent
280cf61e24
commit
91d669a8d2
@ -4,10 +4,10 @@
|
|||||||
* (IFFT)](https://www.geeksforgeeks.org/python-inverse-fast-fourier-transformation/)
|
* (IFFT)](https://www.geeksforgeeks.org/python-inverse-fast-fourier-transformation/)
|
||||||
* is an algorithm that computes the inverse fourier transform.
|
* is an algorithm that computes the inverse fourier transform.
|
||||||
* @details
|
* @details
|
||||||
* This algorithm has an application in use case scenario where a user wants find coefficients of
|
* This algorithm has an application in use case scenario where a user wants
|
||||||
* a function in a short time by just using points generated by DFT.
|
* find coefficients of a function in a short time by just using points
|
||||||
* Time complexity
|
* generated by DFT. Time complexity this algorithm computes the IDFT in
|
||||||
* this algorithm computes the IDFT in O(nlogn) time in comparison to traditional O(n^2).
|
* O(nlogn) time in comparison to traditional O(n^2).
|
||||||
* @author [Ameya Chawla](https://github.com/ameyachawlaggsipu)
|
* @author [Ameya Chawla](https://github.com/ameyachawlaggsipu)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -23,14 +23,15 @@
|
|||||||
*/
|
*/
|
||||||
namespace numerical_methods {
|
namespace numerical_methods {
|
||||||
/**
|
/**
|
||||||
* @brief InverseFastFourierTransform is a recursive function which returns list of
|
* @brief InverseFastFourierTransform is a recursive function which returns list
|
||||||
* complex numbers
|
* of complex numbers
|
||||||
* @param p List of Coefficents in form of complex numbers
|
* @param p List of Coefficents in form of complex numbers
|
||||||
* @param n Count of elements in list p
|
* @param n Count of elements in list p
|
||||||
* @returns p if n==1
|
* @returns p if n==1
|
||||||
* @returns y if n!=1
|
* @returns y if n!=1
|
||||||
*/
|
*/
|
||||||
std::complex<double> *InverseFastFourierTransform(std::complex<double> *p, uint8_t n) {
|
std::complex<double> *InverseFastFourierTransform(std::complex<double> *p,
|
||||||
|
uint8_t n) {
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
return p; /// Base Case To return
|
return p; /// Base Case To return
|
||||||
}
|
}
|
||||||
@ -40,8 +41,8 @@ std::complex<double> *InverseFastFourierTransform(std::complex<double> *p, uint8
|
|||||||
std::complex<double> om = std::complex<double>(
|
std::complex<double> om = std::complex<double>(
|
||||||
cos(2 * pi / n), sin(2 * pi / n)); /// Calculating value of omega
|
cos(2 * pi / n), sin(2 * pi / n)); /// Calculating value of omega
|
||||||
|
|
||||||
om.real(om.real()/n); /// One change in comparison with DFT
|
om.real(om.real() / n); /// One change in comparison with DFT
|
||||||
om.imag(om.imag()/n); /// One change in comparison with DFT
|
om.imag(om.imag() / n); /// One change in comparison with DFT
|
||||||
|
|
||||||
auto *pe = new std::complex<double>[n / 2]; /// Coefficients of even power
|
auto *pe = new std::complex<double>[n / 2]; /// Coefficients of even power
|
||||||
|
|
||||||
@ -52,8 +53,9 @@ std::complex<double> *InverseFastFourierTransform(std::complex<double> *p, uint8
|
|||||||
if (j % 2 == 0) {
|
if (j % 2 == 0) {
|
||||||
pe[k1++] = p[j]; /// Assigning values of even Coefficients
|
pe[k1++] = p[j]; /// Assigning values of even Coefficients
|
||||||
|
|
||||||
} else
|
} else {
|
||||||
po[k2++] = p[j]; /// Assigning value of odd Coefficients
|
po[k2++] = p[j]; /// Assigning value of odd Coefficients
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::complex<double> *ye =
|
std::complex<double> *ye =
|
||||||
@ -76,11 +78,9 @@ std::complex<double> *InverseFastFourierTransform(std::complex<double> *p, uint8
|
|||||||
k2++;
|
k2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n!=2){
|
if (n != 2) {
|
||||||
|
|
||||||
delete[] pe;
|
delete[] pe;
|
||||||
delete[] po;
|
delete[] po;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] ye; /// Deleting dynamic array ye
|
delete[] ye; /// Deleting dynamic array ye
|
||||||
@ -118,16 +118,17 @@ static void test() {
|
|||||||
std::vector<std::complex<double>> r2 = {
|
std::vector<std::complex<double>> r2 = {
|
||||||
{1, 0}, {2, 0}, {3, 0}, {4, 0}}; /// True Answer for test case 2
|
{1, 0}, {2, 0}, {3, 0}, {4, 0}}; /// True Answer for test case 2
|
||||||
|
|
||||||
std::complex<double> *o1 = numerical_methods::InverseFastFourierTransform(t1, n1);
|
std::complex<double> *o1 =
|
||||||
|
numerical_methods::InverseFastFourierTransform(t1, n1);
|
||||||
|
|
||||||
std::complex<double> *o2 = numerical_methods::InverseFastFourierTransform(t2, n2);
|
std::complex<double> *o2 =
|
||||||
|
numerical_methods::InverseFastFourierTransform(t2, n2);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < n1; i++) {
|
for (uint8_t i = 0; i < n1; i++) {
|
||||||
assert((r1[i].real() - o1[i].real() < 0.000000000001) &&
|
assert((r1[i].real() - o1[i].real() < 0.000000000001) &&
|
||||||
(r1[i].imag() - o1[i].imag() <
|
(r1[i].imag() - o1[i].imag() <
|
||||||
0.000000000001)); /// Comparing for both real and imaginary
|
0.000000000001)); /// Comparing for both real and imaginary
|
||||||
/// values for test case 1
|
/// values for test case 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < n2; i++) {
|
for (uint8_t i = 0; i < n2; i++) {
|
||||||
@ -135,10 +136,8 @@ static void test() {
|
|||||||
(r2[i].imag() - o2[i].imag() <
|
(r2[i].imag() - o2[i].imag() <
|
||||||
0.000000000001)); /// Comparing for both real and imaginary
|
0.000000000001)); /// Comparing for both real and imaginary
|
||||||
/// values for test case 2
|
/// values for test case 2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
delete[] t1;
|
delete[] t1;
|
||||||
delete[] t2;
|
delete[] t2;
|
||||||
delete[] o1;
|
delete[] o1;
|
||||||
|
Loading…
Reference in New Issue
Block a user