Error with spectrogram axis

2 次查看(过去 30 天)
Vinci
Vinci 2018-10-14
This is not my code, but I'm using it to help with understanding a similar problem I'm working on. Any help would be appreciated.
I'm getting the error:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in ncode (line 50)
axis([1 fs 1 T ]);
This is the code:
fs = 8000;
phone_No = ['1' '2' '3' '4' '5' '6' '7' '8' '9'];
keypads = ...
['1','2','3','A';
'4','5','6','B';
'7','8','9','C';
'*','0','#','D'];
cfreqs = ones(4,1)*[1209, 1336, 1477, 1633];
rfreqs = [697;770;852;941]*ones(1,4);
x = [];
td1 = 0.2;
td2 = 0.5;
t = 0:fs*td1;
for i = 1:length(phone_No)
if (find(phone_No(i) == keypads));
[a,b] = find (phone_No(i) == keypads);
sig = cos(2*pi*rfreqs(a,b)*t/fs) + cos(2*pi*cfreqs(a,b)*t/fs);
slt = zeros(1,fs*td2);
x = [x,slt,sig];
else
disp('Invalid Input.')
return;
end
end
sound(x,fs)
T = 1/fs;
k = 0:(fs-1);
y = fft(x);
w = 2*pi*k*T; % Frequency in radian
figure(1)
plot(abs(y))
title('FFT magnitude spectrum');
xlabel('Frequency');
ylabel('Magnitude');
figure(2)
plot(x)
title('Dialed signal');
xlabel('Time');
ylabel('Magnitude');
figure(3)
[b, f, T] = specgram(y);
mesh(T, f, abs(b));
axis([1 fs 1 T ]); % -------------Look here, this is line 50----------------------------------------------------
view(150, 50);
title('Spectrogram Magnitude of Dialed Keys');
ylabel('Frequency');
xlabel('Time');
zlabel('Spectrogram Magnitude');
spectrogram(y)

回答(1 个)

Walter Roberson
Walter Roberson 2018-10-15
You have to go back to MATLAB R13 or at most R14SP1 to find information on specgram(), which was considered to be obsoleted as of R14SP2 (that is, it had already been declared old even before that, and R14SP2 was to be the release that finally got rid of it.)
There we find,
"t is a column vector of scaled times, with length equal to the number of columns of B"
I am not sure at the moment how the number of columns of B is calculated, but some tests suggest that the boundary might be that the second parameter to spectgram() might have to exceed 2/3 the length of the input signal for there to be only one column of output. In the case of only one input to specgram(), such as you have, the boundary appears to be that the length of the input must be 383 or less.
After that, the B output of specgram() would have multiple columns, leading to multiple rows in the t output, which gives you problems when you try to build [1 fs 1 T ]
Perhaps you should try [1 fs 1 max(T) ]

类别

Help CenterFile Exchange 中查找有关 Time-Frequency Analysis 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by