简体   繁体   English

如何在 Cuda 中获取从 2D Real 到 Complex FFT 的所有数据

[英]How to get ALL data from 2D Real to Complex FFT in Cuda

I am trying to do a 2D Real To Complex FFT using CUFFT.我正在尝试使用 CUFFT 进行 2D Real To Complex FFT。

I realize that I will do this and get W/2+1 complex values back (W being the "width" of my H*W matrix).我意识到我会这样做并返回 W/2+1 复数值(W 是我的 H*W 矩阵的“宽度”)。

The question is - what if I want to build out a full H*W version of this matrix after the transform - how do I go about copying some values from the H*(w/2+1) result matrix back to a full size matrix to get both parts and the DC value in the right place问题是 - 如果我想在转换后构建这个矩阵的完整 H*W 版本怎么办 - 我如何 go 关于将一些值从 H*(w/2+1) 结果矩阵复制回完整大小矩阵以在正确的位置获取两个部分和 DC 值

Thanks谢谢

I'm not familiar with CUDA, so take that into consideration when reading my response.我不熟悉 CUDA,所以在阅读我的回复时要考虑到这一点。 I am familiar with FFTs and signal processing in general, though.不过,我通常熟悉 FFT 和信号处理。

It sounds like you start out with an H (rows) x W (cols) matrix, and that you are doing a 2D FFT that essentially does an FFT on each row, and you end up with an H x W/2+1 matrix.听起来你从一个 H (rows) x W (cols) 矩阵开始,你正在做一个 2D FFT,基本上对每一行进行 FFT,你最终得到一个 H x W/2+1 矩阵. A W-wide FFT returns W values, but the CUDA function only returns W/2+1 because real data is even in the frequency domain, so the negative frequency data is redundant. W-wide FFT 返回 W 值,但 CUDA function 仅返回 W/2+1,因为实际数据在频域中是偶数,因此负频率数据是多余的。

So, if you want to reproduce the missing W/2-1 points, simply mirror the positive frequency.因此,如果您想重现丢失的 W/2-1 点,只需镜像正频率即可。 For instance, if one of the rows is as follows:例如,如果其中一行如下:

Index Data索引数据
0 12 + i 0 12 + 我
1 5 + 2i 1 5 + 2i
2 6 2 6
3 2 - 3i 3 2 - 3i
... ...

The 0 index is your DC power, the 1 index is the lowest positive frequency bin, and so forth. 0 指数是您的直流电源,1 指数是最低的正频率区间,依此类推。 You would thus make your closest-to-DC negative frequency bin 5+2i, the next closest 6, and so on.因此,您将使最接近 DC 的负频率 bin 为 5+2i,下一个最接近的为 6,依此类推。 Where you put those values in the array is up to you.将这些值放在数组中的位置取决于您。 I would do it the way Matlab does it, with the negative frequency data after the positive frequency data.我会按照 Matlab 的方式来做,在正频率数据之后使用负频率数据。

I hope that makes sense.我希望这是有道理的。

There are two ways this can be acheived.有两种方法可以实现这一点。 You will have to write your own kernel to acheive either of this.您将不得不编写自己的 kernel 来实现其中任何一个。

1) You will need to perform conjugate on the (half) data you get to find the other half. 1)您需要对获得的(一半)数据执行共轭以找到另一半。
2) Since you want full results anyway, it would be best if you convert the input data from real to complex (by padding with 0 imaginary) and performing the complex to complex transform. 2)由于无论如何您都想要完整的结果,最好将输入数据从实数转换为复数(通过用 0 虚数填充)并执行从复数到复数的转换。

From practice I have noticed that there is not much of a difference in speed either way.从实践中我注意到,无论哪种方式,速度都没有太大差异。

I actually searched the nVidia forums and found a kernel that someone had written that did just what I was asking.我实际上搜索了 nVidia 论坛,发现有人写的 kernel 符合我的要求。 That is what I used.那是我用的。 if you search the cuda forum for "redundant results fft" or similar you will find it.如果您在 cuda 论坛中搜索“冗余结果 fft”或类似内容,您会找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM