更改 FFT 内容

发布于 2024-12-21 06:36:33 字数 353 浏览 0 评论 0原文

假设您有一些数据是音调加噪声。

t=0:0.01:10;
y=sin(t) + rand(1,length(t));

我试图降低 fft 中的音调峰值,以便进行 ifft 时仅得到噪声数据。我的算法是一个 for 循环,它循环访问 abs(fft) 的每个索引以查找峰值。如果存在峰值,我会用噪声数据点代替该峰值。

问题是,在完成 fft 后,为了可视化数据,通常我会使用plot(abs(fft))。然而,要做ifft,还需要虚数数据。因此,我不确定我到底会如何“降低峰值”或摆脱它,以便我可以使用 ifft 函数。我想我必须使用虚数。

有什么建议吗? :X

谢谢你的帮助。

Suppose you have some data that is a tone plus noise.

t=0:0.01:10;
y=sin(t) + rand(1,length(t));

I am trying to knock down the tone peaks in the fft so that doing the ifft will result with just the noise data. My algorithm would be a for loop that loops through each index of the abs(fft) to look for a peak. If there is a peak, I would substitute that peak with a noisy datapoint instead.

Problem is, after the fft is done, in order to visualize the data, normally I would use plot(abs(fft)). However, to do ifft, the imaginary data is also needed. Thus, I'm not sure how exactly I would go about "knocking the peak down" or getting rid of it so that I can use the ifft function. I think I would have to work with the imaginary numbers.

Any suggestions? :X

Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

粉红×色少女 2024-12-28 06:36:33

您将不得不使用虚数,但我不明白为什么这是一个问题。您仍然可以使用幅度 (abs) 表示法来查找峰值,但是当您“将它们击倒”时,您将放置另一个复数值。这取决于您如何确定该值应该是什么 - 您可以将其设置为零,插入本地频率,插入随机数...

编辑回复:您的评论:

不要让虚数让您感到困惑。无论如何,它们并不是真正的“想象”!只是为了表示给定频率的正弦波,您需要两个值:幅度和相位。幅度是您习惯看到的,它决定了给定频率的多少。相位决定了相对于某个点(例如t = 0)的偏移,这也非常重要。举例来说,对具有相同频率的信号(例如正弦波和余弦波)进行 FFT - 幅度看起来相同,但相位会不同!如果我们没有相位,IFFT 将不知道是否给我们一个正弦波或余弦波,或者介于两者之间的波。

当然,幅度和相位与实部和虚部不是一回事,但是有一个简单的公式可以将它们转换。无论哪种方式,我们都使用两个数字来表示每个频率。

You will have to work with imaginary numbers, but I don't see why that's a problem. You can still look for the peaks using the magnitude (abs) representation, but when you "knock them down" you will put in place another complex value. It's up to you how you want to determine what this value should be - you could set it to zero, interpolate local frequencies, insert a random number...

Edit re: your comment:

Don't let imaginary numbers confuse you. They're not really "imaginary" anyway! It's just that to represent a sine wave at a given frequency, you need two values: magnitude and phase. Magnitude is what you're used to looking at and it determines how much of a given frequency we have. Phase determines the shift relative to some point (e.g. t = 0), which is also very important. As an example take the FFT to signals (say a sine and a cosine wave) with the same frequency - the magnitudes will look the same, but the phase will be different! If we didn't have phase, IFFT wouldn't know whether to give us a sine wave or a cosine wave, or something in between.

Of course, magnitude and phase are not the same thing as real and imaginary, but there is a simple formula to convert them. Either way we're using two numbers to represent each frequency.

菊凝晚露 2024-12-28 06:36:33

您可以在 abs(fft(y)) 信号中查找“峰值”,并通过查看 fft 本身的方差将其替换为随机复数值,例如

h = fft(y);

peaks = your_peak_finding_algorithm(abs(fft(y)));

real_noise = std(real(h));
imag_noise = std(imag(h));

h(peaks) = real_noise*randn(size(peaks)) + i*imag_noise*randn(size(peaks))

y_new = ifft(h);

However,我强烈质疑这是否真的是您想要做的。如果这是一项学术练习,那么很好,但如果是为了任何类型的实际应用,那么我建议做一些研究。有大量关于降噪以及检测和过滤信号音调的文献。

另请注意 fft 中包含更多信息,而不仅仅是与正弦曲线相关的单个峰值点。请参阅窗口函数。它取决于信号的采样与其带宽的比较,以及噪声的特性。

You could look for "peaks" in the abs(fft(y)) signal and replace them with random complex values by looking at the variance of the fft itself, something like

h = fft(y);

peaks = your_peak_finding_algorithm(abs(fft(y)));

real_noise = std(real(h));
imag_noise = std(imag(h));

h(peaks) = real_noise*randn(size(peaks)) + i*imag_noise*randn(size(peaks))

y_new = ifft(h);

However, I strongly question if this is really what you want to do. If this is an academic exercise, then fine, but if it's for any kind of real application then I'd advise doing some research. There's a ton of literature out there on noise reduction as well as detecting and filtering out tones in signals.

Also Note There is more information in the fft than just a single peak point related to your sinusoid. See Window function. It depends on the sampling of your signal compared to its bandwidth, as well as the properties of the noise.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文