Surface Plot - using a linear vector for displaying x axis

5 Ansichten (letzte 30 Tage)
Matthias
Matthias am 1 Feb. 2012
Hi everybody! I am using 'surf' to display a self-made spectrogram of a speech signal. Here's the code:
% plot spectrogram to axes2
nfft=512;
% reverse axes of vector 'data'
s = data';
% check if signal lenght is an equal number
if mod(length(s),2)
n = length(s)-1;
% crop the signal
s = s(1:n);
data = data(1:n);
else
n = length(s);
end;
% window overlap value
numoverlap = nfft*3/4;
% create hann window
win = hann(nfft, 'periodic');
% determine amount of segments
k = fix((n-numoverlap)/(length(win)-numoverlap));
% create the time vector for entire signal
t=0:((n/fs)/(k-1)):(n/fs);
% create frequency vector
%f = fs/2*linspace(0,1,nfft/2+1); ---> original
f = fs/2*linspace(0,1,nfft/2); % my adaptation for better processing
% predefine the matrix to store the segments
segs=zeros(k,nfft);
% segmentation index
m=1;
% segmentation
for i=1:k
% windowing of the segment
w_s = s(m:nfft+m-1).*win';
segs(i,1:nfft)=w_s;
% next segment
m = m+nfft-numoverlap;
end
% predefine the matrix for the spectral values of the segments
segspec=zeros(k,nfft);
% computation of the fft of the individual segments
for y=1:k
segspec(y,1:nfft)=fft(segs(y,1:nfft));
end
segspec=segspec';
spectral = segspec(1:nfft/2+1,1:k);
surf((log10(abs(spectral))+eps),'EdgeColor','none');
colormap(jet);
view(0,90);
axis([-inf k -inf nfft/2]);
xlabel('Analysis Windows');
ylabel('Frequency Bins');
title('Spectrogram','FontWeight','bold','FontSize',11);
On the x axis, I will now get the frequency bins 1:k. Is it possible to use another vector for displaying the numbers along the x axis, just as I can do with the normal plot function?
Example: t1=1:200; plot(t1,graphdata);
I have tried to look for any solutions in the documentation and online, but I've just hit dead ends on this.
I'd appreciate any suggestions.
  2 Kommentare
Honglei Chen
Honglei Chen am 1 Feb. 2012
You can certainly do surf(x,y,z), and it is documented. Does it work for you?
Matthias
Matthias am 2 Feb. 2012
I have seen that in the documentation, but that doesn't work for me, unfortunately. Somehow, I don't get the matrix dimensions right. It seems I've no idea what y and z should be if x is my 'spectral' matrix that is the spectrogram.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Time-Frequency Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by