Julia DSP期刊N> NFFT是错误,为什么?

发布于 2025-02-10 07:27:22 字数 437 浏览 2 评论 0原文

n = length(s)
# n = 25920169
nfft = 8192
noverlap = Int64(floor(nfft/2))
window = hanning(nfft)
#sp = spectrogram(s, n, noverlap; nfft=nfft, fs=1, window=window)
sp = periodogram(s; nfft=nfft, fs=1, window=window)

引发了错误

nfft must be >= n

,但文档说:

If length(s) < nfft, then the input is padded with zeros. 

这是否意味着NFFT&lt; n应该正确吗?

This

n = length(s)
# n = 25920169
nfft = 8192
noverlap = Int64(floor(nfft/2))
window = hanning(nfft)
#sp = spectrogram(s, n, noverlap; nfft=nfft, fs=1, window=window)
sp = periodogram(s; nfft=nfft, fs=1, window=window)

throws the error

nfft must be >= n

But the documentation says:

If length(s) < nfft, then the input is padded with zeros. 

Doesn't it mean that nfft < n should be correct?

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

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

发布评论

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

评论(1

画离情绘悲伤 2025-02-17 07:27:22

我认为FFT长度nfft应该大于信号长度n以防止混叠。

期刊函数在内部使用FFT,其中长度表示为nfft。从理论上讲,使用FFT时,时间域和频域中的信号都是离散和周期性的,其中该周期由nfft给出。因此,如果指定小于信号长度nnfft,这实际上会在时间域中引入混叠,以使信号周期性使用nfft 。

例如,如果您有一个序列1 2 3 4 5,则假设您的周期也是5,则具有

1 2 3 4 5
          1 2 3 4 5
                    1 2 3 4 5
--------------------------------
      ... 1 2 3 4 5 ...

原始序列。 看起来就像

1 2 3 4 5
      1 2 3 4 5
            1 2 3 4 5
------------------------
  ... 5 7 3 ...

现在,假设您有一个3的时期,那么当您使用n&gt进行此序列时, nfft,您正在使用此别名序列。

您可以手动允许n&gt; nfft通过应用包装(x,nfft)作为bellow并将其输出输出到ofermogram ,MATLAB可以做到这一点。

function wrap(x,nfft)
    y = zeros(eltype(x),nfft)
    for (i,xi) in enumerate(x)
        y[mod1(i,nfft)] += xi
    end
    y
end

例如:

wrap(1:5,3)
3-element Vector{Int64}:
 5
 7
 3

I think that the FFT length nfft should be greater than the signal length n to prevent aliasing.

The periodogram function uses FFT internally, where the length is denoted as nfft. In theory, when using FFT, the signal in both time domain and frequency domain are discrete and periodic, where the period is given by nfft. So, if you specify an nfft that is less than the signal length n, this actually introduces aliasing in the time domain to make the signal periodic with nfft.

For example, if you have a sequence 1 2 3 4 5, assuming that your period is also 5, you have

1 2 3 4 5
          1 2 3 4 5
                    1 2 3 4 5
--------------------------------
      ... 1 2 3 4 5 ...

i.e., the original sequence. Now assume you have a period of 3, then it looks like

1 2 3 4 5
      1 2 3 4 5
            1 2 3 4 5
------------------------
  ... 5 7 3 ...

When you take FFT of this sequence with n > nfft, you are working with this aliased sequence.

You can manually allow for n > nfft by applying the wrap(x,nfft) as bellow and feeding its output to periodogram, MATLAB does exactly that.

function wrap(x,nfft)
    y = zeros(eltype(x),nfft)
    for (i,xi) in enumerate(x)
        y[mod1(i,nfft)] += xi
    end
    y
end

For example:

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