我想知道下面发布的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]);
Update_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]);
Dpectrogram_2 :
答案 0 :(得分:1)
我不认为你正在策划你认为你正在策划的事情。您应该在时域中绘制信号,以确保它看起来像您期望的那样...... plot(x4)
。我认为你认为你的信号是x1后跟x2后跟x3后跟x4。但是,根据您显示的Matlab代码,情况并非如此。
相反,您的信号是x1 + x2 + x3 + x4的总和。因此,由于信号的瞬时启动,您应该看到10,20,30,40 Hz的信号分量以及其他分量。
要获得您想要的信号,您应该执行以下操作:
%get a full-length example of each signal component
t = (0:dt:StopTime-dt);
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 from the four signals above
x = zeros(size(t)); %allocate an empty vector of the correct size
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);
然后,您可以在时域(x
)中绘制新信号plot(x)
,以确保它符合您的要求。最后,您可以执行spectrogram
。
请注意,您将在每个时间段(t1和t2之间,t2和t3之间,然后t3和t4之间)的过渡处看到频谱图中的伪影。信号伪像将反映信号在不同信号频率之间的不连续转换期间是复杂的。