【问题标题】:how to get a correct spectrogram of a non-stationary signal?如何获得非平稳信号的正确频谱图?
【发布时间】:2015-03-01 11:16:09
【问题描述】:

在下面的代码中,我试图获取非平稳信号xspectrogram 运行代码后,我希望看到发布的 inage "image_2" 之类的东西,频率与时间表示。但发布代码的结果是image_1

谁能指导我得到正确的spectrogram

代码

% Time specifications:
Fs = 8000;                       % samples per second
 dt = 1/Fs;                       % seconds per sample
  StopTime = 1;                    % seconds
  t = (0:dt:StopTime-dt);             % seconds
 t1 = (0:dt:.25);
 t2 = (.25:dt:.50);
 t3 = (.5:dt:.75);
 t4 = (.75:dt:1);

 %get a full-length example of each signal component
 x1 = (10)*sin(2*pi*100*t);
 x2 = (10)*sin(2*pi*200*t);
 x3 = (10)*sin(2*pi*300*t);
 x4 = (10)*sin(2*pi*400*t);

  %construct a composite signal
  x = zeros(size(t));
  I = find((t >= t1(1)) & (t <= t1(end)));
  x(I) = x1(I);
  I = find((t >= t2(1)) & (t <= t2(end)));
  x(I) = x2(I);
  I = find((t >= t3(1)) & (t <= t3(end)));
  x(I) = x3(I);
  I = find((t >= t4(1)) & (t <= t4(end)));
  x(I) = x4(I);

  NFFT = 2 ^ nextpow2(length(t));     % Next power of 2 from length of y
   Y    = fft(x, NFFT);
   f    = Fs / 2 * linspace(0, 1, NFFT/2 + 1);
   figure;
   plot(f(1:200), 2 * abs( Y( 1:200) ) );

   T = 0:.001:1;
   spectrogram(x,10,9);
   ylabel('Frequency');
    axis(get(gcf,'children'), [0, 1, 1, 100]);

发布代码的结果:Spectrogram_Image_1

我想得到什么:Image_2:

Update_1,图片 代码

%now call the spectrogram
spectrogram(x, window, noverlap, Nfft, Fs);
ylabel('Frequency');
axis(get(gcf,'children'), [0, 1]);

【问题讨论】:

    标签: matlab signal-processing fft wavelet haar-wavelet


    【解决方案1】:

    首先,就像您第一次问这个问题一样,您是否在时域中绘制了数据(即plot(t, x))并放大了转换以确保您的信号是您认为的?它是否具有您想要的具有不同频率的四个不同周期?

    假设确实如此,我很确定您的问题是您的spectrogram 呼叫没有按照您的意愿进行。我认为你只得到 10 的 NFFT,这意味着你的 bin 是 800 Hz 宽,这不足以解决相隔仅 100 Hz 的频率。

    在我看来,您应该指定更多参数,以便您知道它在做什么。您将指定一个 Nfft 来提供您需要的频率分辨率。分辨率高于 100 Hz(让我们尝试 25 Hz),但不需要太多点,以至于它比您具有稳定频率的持续时间更长(因此,小于 0.25 秒,这意味着小于 2000 个点)。

    要了解如何指定 FFT 的长度,我查看了文档:http://www.mathworks.com/help/signal/ref/spectrogram.html

    根据文档,我会尝试五个参数版本:spectrogram(x,window,noverlap,nfft,fs)

    对于您的代码,Fsx 是您已经定义的,频谱图调用如下所示:

    %define FFT parameters
    des_df_Hz = 25;  %desired frequency resolution for the display, Hz
    Nfft = round(FS / des_df_Hz);  %general rule for FFT resolution
    Nfft = 2*Nfft;  %double the bins to account for spreading due to windowing
    Nfft = 2*round(0.5*Nfft);  %make Nfft an even number
    window = Nfft;  %make your window the same length as your FFT
    noverlap = round(0.95);  %overlap a lot to make the plot pretty
    
    %now call the spectrogram
    spectrogram(x, window, noverlap, Nfft, Fs,'yaxis');
    

    【讨论】:

    • 比你的答案,这似乎是正确的,但轴需要调整。你能告诉我如何正确调整轴吗?我希望水平轴是时间,垂直轴是频率,带有适当的采样“引脚”。请参阅上面发布的 update_1 部分
    • 在 Matlab 频谱图文档 (mathworks.com/help/signal/ref/spectrogram.html) 中,它的示例在垂直轴上显示了您想要的频率。它说将参数'yaxis' 添加到函数调用中。我在上面编辑了我的代码。我还增加了重叠以使频谱图看起来更平滑。
    • 另外,您需要删除 axis 命令,该命令会将 y 轴(即将成为“频率”轴)截断为仅从零到赫兹的范围。现在也是这样。对spectrogram 调用进行编辑后,您需要将axis 命令替换为更简单的命令,例如ylim([0 1000]);
    • 谢谢,一旦我尝试+1,我会告知答案的正确性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 2021-05-15
    • 2014-01-21
    • 2015-06-12
    • 1970-01-01
    相关资源
    最近更新 更多