我想知道spectrogram
下面发布的是否是给定非平稳信号的真实表示。
如果这是一个真实的表示,我对情节中的特定特征有很多疑问......
对于水平轴上的 0->.25,为什么它显示最高频率的信号分量?我假设,给定第一个持续时间t1
,我应该只看到信号的频率x1
。此外,给定第二个持续时间t2
,我应该只看到信号的频率x2
,依此类推。但是,这不是我在下面发布的内容中看到的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);
x1 = (10)*sin(2*pi*10*t1);
x2 = (10)*sin(2*pi*20*t2) + x1;
x3 = (10)*sin(2*pi*30*t3) + x2;
x4 = (10)*sin(2*pi*40*t4) + x3;
NFFT = 2 ^ nextpow2(length(t)); % Next power of 2 from length of y
Y = fft(x4, NFFT);
f = Fs / 2 * linspace(0, 1, NFFT/2 + 1);
%{
figure;
plot(f(1:200), 2 * abs( Y( 1:200) ) );
%}
T = 0:.01:1;
spectrogram(x4,10,9,NFFT);
ylabel('Frequency');
axis(get(gcf,'children'), [0, 1, 1, 50]);
Update_1:当我尝试建议的答案时,我收到了以下信息。
??? Out of memory. Type HELP MEMORY for your options.
Error in ==> spectrogram at 168
y = y(1:length(f),:);
Error in ==> stft_1 at 36
spectrogram(x,10,9,NFFT);
使用的代码:
% Time specifications:
Fs = 8000; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 1; % seconds
t = (0:dt:StopTime-dt); % seconds
%get a full-length example of each signal component
x1 = (10)*sin(2*pi*10*t);
x2 = (10)*sin(2*pi*20*t);
x3 = (10)*sin(2*pi*30*t);
x4 = (10)*sin(2*pi*40*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:.01:1;
spectrogram(x,10,9,NFFT);
ylabel('Frequency');
axis(get(gcf,'children'), [0, 1, 1, 50]);
更新_2
% 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]);
谱图_2: