matlab - What is a spectrogram and how do I set its parameters? -
i trying plot spectrogram of time domain signal given:
n=5000; phi = (rand(1,n)-0.5)*pi; = tan((0.5.*phi)); = 2.*a./(1-a.^2); plot(i); spectrogram(i,100,1,100,1e3);
the problem don't understand parameters , values should given. these values using, referred matlab's online documentation of spectrogram
. new matlab, , not getting idea. appreciated!
before go matlab command does, want know spectrogram is. way you'll more meaning how each parameter works.
a spectrogram visual representation of short-time fourier transform. think of taking chunks of input signal , applying local fourier transform on each chunk. each chunk has specified width , apply fourier transform chunk. should take note each chunk has associated frequency distribution. each chunk centred @ specific time point in time signal, bunch of frequency components. collection of of these frequency components @ each chunk , plotted spectrogram.
the spectrogram 2d visual heat map horizontal axis represents time of signal , vertical axis represents frequency axis. visualized image darker colours means particular time point , particular frequency, lower in magnitude frequency component is, darker colour. similarly, higher in magnitude frequency component is, lighter colour.
here's 1 perfect example of spectrogram:
source: wikipedia
therefore, each time point, see distribution of frequency components. think of each column frequency decomposition of chunk centred @ time point. each column, see varying spectrum of colours. darker colour is, lower magnitude component @ frequency , vice-versa.
so!... you're armed that, let's go how matlab works in terms of function , parameters. way calling spectrogram
conforms version of function:
spectrogram(x,window,noverlap,nfft,fs)
let's go through each parameter 1 one can greater understanding of each does:
x
- input time-domain signal wish find spectrogram of. can't simpler that. in case, signal want find spectrogram of defined in following code:n=5000; phi = (rand(1,n)-0.5)*pi; = tan((0.5.*phi)); = 2.*a./(1-a.^2);
here,
i
signal want find spectrogram of.window
- if recall, decompose image chunks, , each chunk has specified width.window
defines width of each chunk in terms of samples. discrete-time signal, know signal sampled particular sampling frequency , sampling period. can determine how large window in terms of samples by:window_samples = window_time/ts
ts
sampling time of signal. setting window size empirical , requires lot of experimentation. basically, larger window size, better frequency resolution you're capturing more of frequencies, time localization poor. similarly, smaller window size, better localization have in time, don't great of frequency decomposition. don't have suggestions here on optimal size is... why wavelets preferred when comes time-frequency decomposition. each "chunk", chunks decomposed smaller chunks of dynamic width mixture of time , frequency localization.noverlap
- way ensure frequency localization chunks overlapping. proper spectrogram ensures each chunk has number of samples overlapping each chunk ,noverlap
defines how many samples overlapped in each window. default 50% of width of each chunk.nfft
- taking fft of each chunk.nfft
tells how many fft points desired computed per chunk. default number of points largest of either 256, orfloor(log2(n))
n
length of signal.nfft
gives measure of how fine-grained frequency resolution be. higher number of fft points give higher frequency resolution , showing fine-grained details along frequency axis of spectrogram if visualised.fs
- sampling frequency of signal. default 1 hz, can override whatever sampling frequency signal at.
therefore, should take out of can't tell how set parameters. depends on signal have, above explanation give better idea of how set parameters.
good luck!
Comments
Post a Comment