Pregunta

The MATLAB documentation examples for the spectrogram function gives examples that have the frequency axis set to [0 500]. Can I change this to something like [0 100]? Obviously running the axis command will do this for me, but that adjusts the end result and "blows up" the resultant plot, make it pixelated. I am basically looking to build a spectrogram that only looks for frequencies between 0-100, not rescaling after building the spectrogram.

Here's an example from that documentation:

T = 0:0.001:2;
X = chirp(T,0,1,150);
spectrogram(X,256,250,256,1E3,'yaxis');

This produces the following: Linear chirp spectrogram

Everything below 350Hz is unneeded. Is there a way to not include everything between 350 to 500 when building the spectrogram, rather than adjusting axes after the fact?

¿Fue útil?

Solución

From the documentation:

[S,F,T] = spectrogram(x,window,noverlap,F) uses a vector F of frequencies in Hz. F must be a vector with at least two elements. This case computes the spectrogram at the frequencies in F using the Goertzel algorithm. The specified frequencies are rounded to the nearest DFT bin commensurate with the signal's resolution. In all other syntax cases where nfft or a default for nfft is used, the short-time Fourier transform is used. The F vector returned is a vector of the rounded frequencies. T is a vector of times at which the spectrogram is computed. The length of F is equal to the number of rows of S. The length of T is equal to k, as defined above and each value corresponds to the center of each segment.

Does that help you?

Otros consejos

The FFT is so fast that it is better to increase the resolution and then just discard the unwanted data. If you need better spectral resolution (more frequency bins) then increase the FFT size. To get smoother looking spectrum in time dimension, increase the noverlap value to reduce the increments for each consequtive FFT. In this case you would not specify the F. If FFT size is 1024 then you get 1024/2+1 frequency bins.

FFTN = 512;
start = 512*(350/500); % Only care about freq bins above this value
WIN_SIZE = FFTN;
overlap = floor(FFTN*0.8);
[~,F,T,P] = spectrogram(y, WIN_SIZE, overlap, FFTN);
f = 0:(length(F)-1);
f = f*((Fs/2)/length(F));
P = P(start:512,:);
f = f(1,start:512);
imagesc(T,f,10*log10(P),[-70 20]); 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top