複雑な2Dアレイが与えられた場合、C++は2DFFTインプレースで実行します
高速フーリエ変換(FFT)は、離散フーリエ変換(DFT)とその逆関数を計算するアルゴリズムです。基本的に、フーリエ解析は時間(または空間)を周波数に、またはその逆に変換します。 FFTは、DFT行列をスパース(ほとんどゼロ)因子の積に因数分解することにより、変換を迅速に計算します。
アルゴリズム
Begin Declare the size of the array Take the elements of the array Declare three arrays Initialize height =size of array and width=size of array Create two outer loops to iterate on output data Create two outer loops to iterate on input data Compute real, img and amp. End
サンプルコード
#include <iostream>
#include <math.h>
using namespace std;
#define PI 3.14159265
int n;
int main(int argc, char **argv) {
cout << "Enter the size: ";
cin >> n;
double Data[n][n];
cout << "Enter the 2D elements ";
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> Data[i][j];
double realOut[n][n];
double imgOut[n][n];
double ampOut[n][n];
int height = n;
int width = n;
for (int yWave = 0; yWave < height; yWave++) {
for (int xWave = 0; xWave < width; xWave++) {
for (int ySpace = 0; ySpace < height; ySpace++) {
for (int xSpace = 0; xSpace < width; xSpace++) {
realOut[yWave][xWave] += (Data[ySpace][xSpace] * cos(2 *
PI * ((1.0 * xWave * xSpace / width) + (1.0 * yWave * ySpace /
height)))) / sqrt(width * height);
imgOut[yWave][xWave] -= (Data[ySpace][xSpace] * sin(2 * PI
* ((1.0 * xWave * xSpace / width) + (1.0 * yWave * ySpace / height)))) /
sqrt( width * height);
ampOut[yWave][xWave] = sqrt(
realOut[yWave][xWave] * realOut[yWave][xWave] +
imgOut[yWave][xWave] * imgOut[yWave][xWave]);
}
cout << realOut[yWave][xWave] << " + " <<
imgOut[yWave][xWave] << " i (" << ampOut[yWave][xWave] << ")\n";
}
}
}
} 出力
Enter the size: 2 Enter the 2D elements 4 5 6 7 4.5 + 6.60611e-310 i (4.5) 11 + 6.60611e-310 i (11) -0.5 + -8.97448e-09 i (0.5) -1 + -2.15388e-08 i (1) 4.5 + 6.60611e-310 i (4.5) -2 + -2.33337e-08 i (2) -0.5 + -8.97448e-09 i (0.5) 0 + 5.38469e-09 i (5.38469e-09)
-
C++での並べ替え
このセクションでは、C++で並べ替えアルゴリズムを実行する方法を説明します。並べ替えられた配列は、各要素が数値、アルファベット順などの順序で並べ替えられた配列です。バブルソート、挿入ソート、選択ソート、マージソート、クイックソート、ヒープソートなど、数値配列をソートするための多くのアルゴリズムがあります。選択ソートを使用した配列のソートの詳細については、以下を参照してください。 選択ソートは、ソートされた配列を生成するソート方法です。これは、配列内の最小の要素を繰り返し見つけて、ソートされていない部分の先頭にある要素と交換することによって行われます。 選択ソートを使用してソートされた配列を
-
複素数の乗算を実行するC++プログラム
複素数は、a + biとして表される数です。ここで、iは虚数、aとbは実数です。複素数の例は次のとおりです- 2+3i 5+9i 4+2i 複素数の乗算を実行するプログラムは次のとおりです- 例 #include<iostream> using namespace std; int main(){ int x1, y1, x2, y2, x3, y3; cout<<"Enter the first complex number : "<<endl; cin&g