fft 相关问题

快速傅里叶变换的简称,是快速计算离散傅里叶变换的一组算法中的任何一种。

在 Python 中使用 FFT 和 IFFT 在偶数点采样时,离散函数变得复杂,同时自由传播实数函数

我的代码涉及使用傅里叶变换和傅里叶逆变换传播实函数。具体来说,该函数演化为 ∂ψ(z,t)/∂t - v ∂ψ(z,t)/∂z =0 我通过Fou解决了这个问题...

回答 1 投票 0

如何在矢量数据的情况下应用FFT?

我编写了以下类来计算 3d 向量列表的自相关。 我从这个链接中获取了公式 公共静态类 AutocorrVec3 { 私有静态双 C(int t, List 我编写了以下类来计算 3d 向量列表的自相关。 我从这个链接获取了公式 public static class AutocorrVec3 { private static double C(int t, List<Vec3> vectors) { int n = vectors.Count; if (t >= n || t < 0) throw new ArgumentException("Invalid value for t. It must be between 0 and n-1."); double sum = 0; for (int i = 0; i < n - t; i++) { sum += vectors[i].Dot(vectors[i + t]); } return sum / (n - t); } public static (List<double> taus, List<double> autocorrs) GetAutoCorrelationPoints(List<Vec3> vectors, int maxLag) { var tValues = new List<double>(); var cResults = new List<double>(); double c0 = C(0, vectors); // This is the normalization factor Console.WriteLine($"Normalization factor: {c0}"); for (int lag = 0; lag <= maxLag; lag++) // Start from 0 to include the autocorrelation at lag 0 { try { double cValue = C(lag, vectors); Console.WriteLine($"Lag={lag}, Raw Autocorr={cValue}, Normalized Autocorr={cValue / c0}"); tValues.Add(lag); cResults.Add(cValue / c0); // Normalization is done here } catch (ArgumentException ex) { Console.WriteLine(ex.Message); break; } } return (tValues, cResults); } } 问题是,GetAutoCorrelationPoints()非常慢。例如,我需要转换 24 个文件,每个文件包含 10000000 个 3d 矢量。 24小时后,连一个数据文件都无法完成计算。 在这种情况下我该如何应用FFT? 我想用MathNet.Numerics。 using System; using System.Collections.Generic; using System.Numerics; using MathNet.Numerics.IntegralTransforms; namespace FourierTransformCSharp { public static class AutocorrVec3 { // Compute the autocorrelation of a time series using FFT public static double[] ComputeAutocorrelationUsingFFT(List<Vec3> vectors) { int n = vectors.Count; // Create a zero-padded list double the size of the original for FFT var paddedVectors = new Complex[2 * n]; for (int i = 0; i < n; i++) { // Convert vector to complex number with magnitude as real part paddedVectors[i] = new Complex(vectors[i].Magnitude(), 0); } for (int i = n; i < 2 * n; i++) // Zero padding { paddedVectors[i] = Complex.Zero; } // Perform FFT on the zero-padded list Fourier.Forward(paddedVectors, FourierOptions.Default); // Compute power spectrum (magnitude squared) for (int i = 0; i < paddedVectors.Length; i++) { var magnitude = paddedVectors[i].Magnitude; paddedVectors[i] = new Complex(magnitude * magnitude, 0); } // Perform Inverse FFT to obtain the autocorrelation function Fourier.Inverse(paddedVectors, FourierOptions.Default); // Extract the real parts as the autocorrelation result var autocorr = new double[n]; for (int i = 0; i < n; i++) { autocorr[i] = paddedVectors[i].Real; } // Normalize the autocorrelation result var normalizationFactor = autocorr[0]; for (int i = 0; i < n; i++) { autocorr[i] /= normalizationFactor; } return autocorr; } // Calculate autocorrelation of vector time series at lag t public static double C(int t, List<Vec3> vectors) { double[] autocorr = ComputeAutocorrelationUsingFFT(vectors); return autocorr[t]; } // Get autocorrelation values for lags from 0 to maxLag public static (List<int> taus, List<double> autocorrs) GetAutoCorrelationPoints(List<Vec3> vectors, int maxLag) { List<int> taus = new List<int>(); List<double> autocorrs = new List<double>(); double[] autocorr = ComputeAutocorrelationUsingFFT(vectors); for (int t = 0; t <= maxLag && t < vectors.Count; t++) { taus.Add(t); autocorrs.Add(autocorr[t]); } return (taus, autocorrs); } // Parallel computation is unnecessary as FFT-based autocorrelation is already fast // Use GetAutoCorrelationPoints for parallel computation } public class Vec3 { public double X { get; } public double Y { get; } public double Z { get; } public Vec3(double x, double y, double z) { X = x; Y = y; Z = z; } // Compute the magnitude of the vector public double Magnitude() { return Math.Sqrt(X * X + Y * Y + Z * Z); } } public class AutocorrelationDriver { public static void Main() { // Define your list of 3D vectors List<Vec3> vectors = new List<Vec3> { new Vec3(1, 1, 1), new Vec3(2, 2, 2), new Vec3(3, 3, 3), new Vec3(4, 4, 4), new Vec3(5, 5, 5) }; // Compute the autocorrelation var aurocorr = AutocorrVec3.GetAutoCorrelationPoints(vectors, vectors.Count - 1); // Output the results Console.WriteLine("Lag\tAutocorrelation"); for (int i = 0; i < aurocorr.taus.Count; i++) { Console.WriteLine($"{aurocorr.taus[i]}\t{aurocorr.autocorrs[i]}"); } Console.ReadKey(); } } } 上面的代码是我写的。 正确的输出如下: 但是,我编写的代码给出了以下输出: Lag Autocorrelation 0 1 1 0.727272727272727 2 0.472727272727273 3 0.254545454545455 4 0.0909090909090911 如何修复我的代码? 就目前而言,基于 FFT 的计算实际上没有任何问题。您记得在所有正确的位置进行零填充(做得很好),它给出了我对您的测试数据所期望的答案。 这两个代码之间的差异是因为您忘记了通过贡献滞后分量 1/(n-t) 的数量来标准化 FFT 计算的输出。 应用该校正进行 FFT 相关性计算可得到与玩具测试数据上的普通方法完全相同的答案。 我不太确定将相关函数应用于矢量大小的优点,但这完全是另一回事。这是示例数据的表格。 数据 滞后 sum(a(i).a(i+t)) 规范 /(n-t) 范数 C(t,v5) 1 0 55 1 0.2 1 2 1 40 0.727272727 0.181818182 0.909090909 3 2 26 0.472727273 0.157575758 0.787878788 4 3 14 0.254545455 0.127272727 0.636363636 5 4 5 0.090909091 0.090909091 0.454545455 您可以通过一种方法来进一步优化它,方法是返回向量中的幂,而不是返回magnitude = sqrt(X.X+Y.Y+Z.Z),然后在返回“X.X+Y.Y+”时对其进行平方Z.Z" 它已准备好用于计算功率谱。我真的不确定这个计算有什么物理解释。 顺便说一句,通过使用 FFT 的实数到复数共轭对称版本,您几乎可以将速度提高一倍并将内存需求减半。这避免了将真实数据提升为零虚部的复杂数据。首先尝试“按原样”,因为对于较大的 N,Nlog N 比 N^2 小很多。 但是速度提高两倍可能仍然值得付出额外的努力。

回答 1 投票 0

如何从信号的FFT中获得频率和相应的幅度?

我有以下1.2Hz/9Hz/15Hz信号 将 numpy 导入为 np 总时间 = 5 采样频率 = 100 t = np.linspace(0, 总时间, 总时间 * 采样频率, 端点=False) 信号 = np.s...

回答 1 投票 0

使用 MATLAB 计算傅里叶系数

在此输入图像描述 由于我是 MATLAB 的新手,我对 MATLAB 的函数不太熟悉,我想知道如何计算

回答 1 投票 0

如何在信号的 FFT 中获得正确的频率幅度

我有以下1Hz/10Hz信号 将 numpy 导入为 np 总时间 = 5 采样频率 = 200 t = np.linspace(0, 总时间, 总时间 * 采样频率) 信号 = np.sin(2 * np.pi * 1 * t)...

回答 1 投票 0

使用 np.fft.fft2 和 cv2.dft 再现相位谱。为什么结果不相似?

另一个问题是询问使用 cv2.dft 时获取幅度谱和相位谱的正确方法。 我的答案仅限于 numpy 方法,然后我认为使用 OpenCV 来实现此目的

回答 1 投票 0

如何使用 FFT 确定频率相关幅度

我正在尝试通过简单地生成输入信号并通过频率扫描测量输出来测量和计算音频设备的频率响应。 这就是我想要实现的目标

回答 1 投票 0

OpenCV Phase() 函数在这种边缘情况下是否正常工作?

我正在使用 OpenCV 3.2.0 进行一些傅立叶空间计算。为了在逆 DFT 后获得相位图像,我尝试使用 cv::phase() 但我注意到在某些情况下,它返回的值接近 2...

回答 1 投票 0

在Python中舍入很小/接近零的复数值

考虑以下序列/信号: 将 numpy 导入为 np 从 scipy.fft 导入 fft # %% 离散数据 x = np.array([0.7966875, 0.7966875, 0.7966875, 0.7966875, 0.7966875, 0.7966875, 0.79...

回答 1 投票 0

如何使用 trapz 函数与积分函数

我的代码使用积分函数工作,但我希望使用 trapz 函数来实现它。 fc = 5*10^6; fb = 0.2*10^6; F = [0:10000:10^7]; Tb=1/fb; 序列 = [0 1 0 1 ...

回答 1 投票 0

有没有办法用 scipy.fft 在傅立叶空间中进行数值积分?

我有兴趣在使用 scipy 对一些数据进行 fft 处理后集成到傅立叶空间中。我一直在关注傅立叶空间中的堆栈交换后数值积分......

回答 1 投票 0

如何从NumPy数组中提取主频率?

我正在研究神经元群体的模拟,并且想从它们的局部场势中提取主频率。这仅采用单个值向量的形式,wh...

回答 1 投票 0

使用Python执行傅里叶分析进行图像重建

我正在尝试对使用 Python 生成的一些形状进行傅立叶分析。我设法在图像上获得 2D 傅立叶变换并应用高斯滤波器,但是相反......

回答 1 投票 0

为什么 python np.fft.fft() 结果和 C# Fourier.Forward() 结果不同?

我正在尝试根据 I、Q 数据制作图表。 输入是通过组合 C# 和 Python 中 IQ 数据中的 I 和 Q 创建的复数数组。 Python: signal.append(complex( I[i],Q[i])) C#:是...

回答 1 投票 0

使用Python执行傅里叶分析

我正在尝试对使用 Python 生成的一些形状进行傅立叶分析。我设法在图像上获得 2D 傅立叶变换并应用高斯滤波器,但是相反......

回答 1 投票 0

什么是“无为”卷积核

如果我尝试在频率空间中执行卷积内核 - 什么是“不执行任何操作”内核。换句话说,如果我在应用内核后查看图像,并在频率空间中对其进行标准化,我

回答 2 投票 0

如何在 MatLab 上为我的 txt 文件数据绘制傅里叶谱? [重复]

我有一个每秒采集的 txt 文件中的地面磁数据,我想绘制它的傅立叶光谱。 我注意到 MatLab 上的频谱图方程需要这个参数(窗口、noverlap、n...

回答 1 投票 0

R:逆 fft() 来确认我的手动 DFT 算法不准确?

使用 R,在评估我自己手动实现 DFT 的一些准确性指标之前,我想通过执行以下操作来对 stats::fft() 的执行情况进行健全性检查: sig.ts = ts( sin(2*pi*

回答 1 投票 0

Scipy 计算 FFT 时振幅不正确

当尝试计算此堆叠正弦信号的 FFT 时,所得 FFT 与初始输入不匹配。该代码初始化一个结果数组,其中填充了不同

回答 1 投票 0

检测文本字符串/复制文本中的重复

我有一个输入表单,用户可以在其中上传测试报告,最小长度为100字。有些用户写的比这个少,只是简单地复制他们写的内容,直到达到 100 字的门槛。 我...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.