C++ DFT算法和卷积。怎么了?

C++ DFT算法和卷积。怎么了?,c++,dft,C++,Dft,#包括 使用std::vector; #包括 使用std::complex; 使用std::polar; typedef复合物; #定义Pi 3.14159265358979323846 //直接傅里叶变换 矢量测向(常数矢量和输入) { 常数int N=in.size(); 矢量输出(N); 对于(int k=0;k

#包括
使用std::vector;
#包括
使用std::complex;
使用std::polar;
typedef复合物;
#定义Pi 3.14159265358979323846
//直接傅里叶变换
矢量测向(常数矢量和输入)
{
常数int N=in.size();
矢量输出(N);
对于(int k=0;k

谁能说,怎么了

也许我不了解这个算法的实现细节。。。但是我找不到它

另外,我需要计算卷积

但我找不到测试示例

更新

//卷积。我想x0.size==x1.size
向量卷积(常数向量&x0,常数向量&x1)
{
常数int N=x0.size()

向量tmp(N);
对于(int i=0;i
}

变换看起来很好,但程序中没有进行卷积的东西

更新:卷积码需要在元素相乘之前首先对输入进行前向变换。

检查库“用于计算离散傅立叶变换(DFT)”及其C#)也许也是;)


祝你好运

我真的不知道你到底在问什么,但你的DFT和IDFT算法在我看来是正确的。可以使用DFT和IDFT执行卷积,其中基本上表示
f**g=IDFT(DFT(f)*DFT(g))
,其中
**
是循环卷积,
*
是简单乘法

要使用DFT计算线性卷积(非循环),必须对每个输入进行零填充,以便仅对零值样本进行循环环绕,而不影响输出。每个输入序列需要进行零填充,长度为
N>=L+M-1
,其中
L
M
是输入序列的长度。然后执行如上所示的循环卷积,第一个
L+M-1
样本是线性卷积输出(超出此范围的样本应为零)


注意:使用DFT和IDFT算法执行卷积比直接计算效率要低得多。仅当使用FFT和IFFT(O(NlogN))算法代替DFT和IDFT(O(N^2))时,优势才会出现

在原始代码中,向量头丢失,using语句也丢失(或者,用std限定向量)。卷积码是不完整的,不能像那样使用
向量
;必须指定值类型(即使用
vector

#include <vector>
using std::vector;

#include <complex>
using std::complex;
using std::polar;

typedef complex<double> Complex;

#define Pi 3.14159265358979323846

// direct Fourier transform
vector<Complex> dF( const vector<Complex>& in )
{
 const int N = in.size();

 vector<Complex> out( N );

 for (int k = 0; k < N; k++)
 {
  out[k] = Complex( 0.0, 0.0 );

  for (int n = 0; n < N; n++)
  {
   out[k] += in[n] * polar<double>( 1.0, - 2 * Pi * k * n / N );
  }
 }

 return out;
}

// inverse Fourier transform
vector<Complex> iF( const vector<Complex>& in )
{
 const int N = in.size();

 vector<Complex> out( N );

 for (int k = 0; k < N; k++)
 {
  out[k] = Complex( 0.0, 0.0 );

  for (int n = 0; n < N; n++)
  {
   out[k] += in[n] * polar<double>(1, 2 * Pi * k * n / N );
  }

  out[k] *= Complex(  1.0 / N , 0.0 );
 }

 return out;
}
// convolution. I suppose that x0.size == x1.size vector convolution( const vector& x0, const vector& x1) { const int N = x0.size();

vector<Complex> tmp( N );

for ( int i = 0; i < N; i++ )
{
    tmp[i] = x0[i] * x1[i];
}

return iF( tmp );