Is it possible to add an option to the SPECTROGRAM function to return/ display the DC

Illustration
Nevaeh - 2021-03-13T13:45:40+00:00
Question: Is it possible to add an option to the SPECTROGRAM function to return/ display the DC

Is it possible to add an option to the SPECTROGRAM function to return/ display the DC frequency in the center of the axis in the Signal Processing Toolbox 6.11 (R2009a)? When I execute the following commands to get the SPECTROGRAM plot:     % sample rate Fs = 1024; % number of samples of signal to generate N = 4192; % complex sinusoid frequency (negative) Fc = -128; % generate complex sinusoid Ts = 1/Fs; n = 0:N-1; t = n*Ts; x = exp(1i*2*pi*Fc*t); % the frequency reported by plot is not Fc but 1024 + Fc; spectrogram(x,hamming(128),64,128,Fs); The plot shows only positive frequencies. I know that I can pass the frequency vector to view the negative frequency components as well but an option to specify that the center of the axis should be the DC frequency would be much easier to use.  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

The option to specify that the DC frequency be at the center of the frequency axis is not available in the Signal Processing Toolbox.
To work around this issue, pass the frequency vector in the call to the SPECTROGRAM function like this:
 
NFFT = 128;

f_vec = [-floor(NFFT/2) : ceil(NFFT/2)-1] * Fs/NFFT;

spectrogram(x,hamming(128),64,f_vec,Fs);


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!