0

在下面发布的图片中,我正在尝试TFR使用STFT. 在发布的代码中,我指定了参数T = 0:.001:1;,例如,当我将其修改为时,T = 0:.001:2;绘图水平轴上的值范围会发生变化,尽管它被标记为Frequency.

现在,我想更改所示图上水平轴和垂直轴的值范围。我怎样才能做到这一点?

注意:用于生成所示图的代码是:

T = 0:.001:1;
spectrogram(x4,128,50,NFFT);

代码

% 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);

  %two freqs. = abs(f1 - f2), that's why, x1 is plotted with 2 freqs.
  x1 = (10)*sin(2*pi*30*t1);
  x2 = (10)*sin(2*pi*60*t2) + x1;
  x3 = (10)*sin(2*pi*90*t3) + x2;
  x4 = (10)*sin(2*pi*120*t4) + x3;
  %x5 = (10) * sin(2*pi*5*t5);
  %x6 = x1 + x2 + x3 + x4 + x5;

  NFFT = 2 ^ nextpow2(length(t));     % Next power of 2 from length of y
  Y    = fft(x3, 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(x4,10,9,31);
   axis(get(gcf,'children'), [0, 1,0,100]);

% Plot the signal versus time:
figure;
xlabel('time (in seconds)');
ylabel('Amplitude');
title('non-stationary Signal versus Time');

 hold on
 plot(t1,x1,'r');
plot(t2,x2,'g');
plot(t3,x3,'b');
plot(t4,x4,'black');
%plot(t5,x5,'y');
%plot(t, x6,'black');
legend('x1 = (10)*sin(2*pi*15*t1) + (10)*sin(2*pi*8*t1)', 'x2 = (10)*sin(2*pi*25*t2) + x1',   
'x3 = (10)*sin(2*pi*50*t3) + x2', 'x4 = (10)*sin(2*pi*75*t4) + x3', ...
'Location',  'SouthWest');

图片

在此处输入图像描述

新结果_1 在此处输入图像描述

4

1 回答 1

0

想法:获取axis用于绘制频谱图并相应地设置其属性。例如,假设您希望将x范围限制为 [0, 0.5] 并将y限制为 [100, 200],则:

%'old code here'
%' . . . '
spectrogram(x4,128,50,NFFT);

%'new code here'
axis(get(gcf,'children'), [0, 0.5, 100, 200]);

说明:添加的单行gets 来自当前图形的子句柄gcf(假定由 创建spectrogram),然后[xmin, xmax, ymin, ymax]通过axis调用将其范围设置为。

Nota Bene:我假设您只需要重新缩放轴,而不是重新计算spectrogram不同数据的轴。

此外,我假设频谱图与其他轴共享其图形。

此外,扩展轴范围而不是限制它可能不会给您预期的结果(一句话:丑陋)。

于 2014-12-30T13:30:39.637 回答