Why do I receive an error when I use the SPECTROGRAM

J
Jamespiper · Feb 22, 2021 · 2K views
Question
Why do I receive an error when I use the SPECTROGRAM function if the length of the window is equal to the signal length in Signal Processing Toolbox 6.13 (R2010a)? I try to plot the spectrogram of a signal using the following code (data file attached):     load emg; x = emg; lenx = length(x); window = ones(1, lenx); nfft = lenx/8; fs = 1000; noverlap = 32; F = [1:1:fs/2]; spectrogram(x,window,noverlap,F,fs) The error I receive is the following: ??? Error using ==> surf at 78 Z must be a matrix, not a scalar or vector. Error in ==> spectrogram>displayspectrogram at 250 hndl = surf(args{:},'EdgeColor','none'); Error in ==> spectrogram at 184 displayspectrogram(t,f,Pxx,isFsnormalized,faxisloc);
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 25, 2026
The ability to have the length of the signal to be the same as the length of the window is not available for the SPECTROGRAM function in Signal Processing Toolbox 6.13 (R2010a).
 
As a workaround, use the IMAGESC function as follows:
 
 
T = 0:0.001:2;

X = chirp(T,100,1,200,'q');

[S, F, T, P] = spectrogram(X,128,120,128,1E3); 

imagesc(F, T(1), 10*log10(P(:,1).')); 

axis xy; axis tight; 

xlabel('Frequency (Hz)');

ylabel('Time');

title('Quadratic Chirp');
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!