【问题标题】:How to get the sample frequency axis in R?如何获得R中的采样频率轴?
【发布时间】:2015-04-07 01:51:42
【问题描述】:

我试图在 R 中的频域中绘制时间序列数据。我有一个 csv 文件,其中包含 xyz 的列/信号。信号已以 50 Hz 的频率采样。数据长度为N=651

我为列/信号x做了以下步骤:

  1. 信号x的FFT:

    y <- fft(data$x)

  2. 计算信号x的幅值:

    mag <- sqrt(Re(y)^2+Im(y)^2)

  3. 绘制数据:

    plot(mag, xlab="Samples",ylab="Strength", type="l", col="blue", xlim=c(0,60), main="Spectrum",t="h",lwd=2)

我想要的是在频率(Hz)而不是样本数中获得 x 轴。最后,我想得到一个 y 轴(强度)与 x 轴(Hz)的图。

我想要这样的频率轴:10Hz、20Hz、30Hz、40Hz、50Hz 等。

我需要做什么才能获得以 Hz 为单位的频率轴而不是样本数?

【问题讨论】:

  • 请绘制您的最终 fft 频谱,以便我们尝试确定您的频谱是否正确,我感觉您可能不了解 FFT 分箱。

标签: r plot fft frequency-analysis


【解决方案1】:

这就是你所追求的吗?

plot(mag, 
     xlab="Samples",
     ylab="Strength",
     type="l",
     col="blue",
     xlim=c(0,
            60),
     main="Spectrum",
     t="h",
     lwd=2,
     axes=F)# don't plot the default axes
#build our own axes with labels
box()
axis(2)
ticks <- axTicks(1)
axis(1,at=ticks,labels=paste0(format(ticks),'Hz'))

【讨论】:

    猜你喜欢
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-04
    • 1970-01-01
    • 2018-06-08
    • 2019-03-19
    • 1970-01-01
    相关资源
    最近更新 更多