Short-time Fourier analysis: spectrogram function

Source: Internet
Author: User
Tags local time scalar
Introduction to 1.spectrogram parametersFunction: The spectrum diagram of the signal is obtained by using the short-time Fourier transform.
Grammar:
[S,f,t,p]=spectrogram (X,WINDOW,NOVERLAP,NFFT,FS)
[S,f,t,p]=spectrogram (X,WINDOW,NOVERLAP,F,FS)
Note: When using no output parameters, the spectrum map will be automatically plotted, and the output parameters will return the short-time Fourier transform of the input signal. Of course, you can also draw the spectrogram from the function's return value s,f,t,p, see example. Parameters:
x---The vector of the input signal.
By default, there is no subsequent input parameter, X will be divided into 8 segments to do transformation processing, if X can not be divided into 8 segments, it will do truncation processing. By default, the default values for other parameters are: Window ---window functions, the default is Nfft length of the Hamming window Hamming; noverlap number of overlapping samples---each segment, the default value is 50% overlap between the segments; nfft---Do the length of the FFT transform, the default is 256 and the maximum value is greater than the minimum 2 power of the length of each segment. In addition, this parameter can specify a frequency vector F, in addition to using a constant; FS---sampling frequency, the default value is normalized frequency.
Window ---window functions, if window is an integer, X will be divided into the window segment, with the Hamming window function added to each segment. If window is a vector, X will be divided into length (window) segments, each with window functions specified by the window vector. So if you want to get the function of the Specgram function, just specify a 256-length Hann window.
Noverlap---The number of sample points that overlap between segments. It must be an integer that is less than window or length (window). It means that two adjacent windows are not tails, but there are overlapping parts of two windows.
Nfft---Calculating the points of discrete Fourier transform。 It needs to be scalar.
Fs---sampling frequency Hz, if specified as [], the default is 1Hz.
Short-time Fourier transform for S---input signal x。 Each column contains an estimate of the frequency component of a short-term local time, the time increases along the column, and the frequency increases along the line. If x is a complex signal of length Nx, then S is a complex matrix of nfft row K columns, where k depends on window, if window is a scalar, k = fix ((nx-noverlap)/(WINDOW-NOVERLAP)), or if window is a vector, K = Fix ((nx-noverlap)/(Length (window)-noverlap)). For real signal X, if Nfft is even, the number of lines of S is (nfft/2+1), if Nfft is odd, the number of rows is (nfft+1)/2, and the number of columns is as above.
f---Use the f-frequency vector in the input variable,The function uses the Goertzel method to calculate the spectrogram at the frequency specified by F. The specified frequency is rounded to the nearest DFT container (BIN) associated with the signal resolution. In other uses of the NFFT syntax, the short-time Fourier transform method will be used. For the F vector in the return value, the frequency of rounding, whose length is equal to the number of lines of S.
T---The time point of the spectral graph calculation, whose length is equal to the k defined above, and the value is the midpoint of each segment.

p---Energy spectral density PSD (Power spectral Density), for real signals, p is the unilateral periodic estimation of each segment of PSD, and for complex signals, p is a bilateral PSD when the F frequency vector is specified. The elements of the P-matrix are calculated as follows P (I,J) =k| S (I,J), wherein the k is a real value scalar, defined as follows for a single-sided PSD, the formula is as follows, where W (n) Represents the window function, FS is the sampling frequency, at 0 frequency and Nyquist frequency, the molecular factor 2 is changed to 1; 2. Questions about drawing

If the sampling frequency is not specified, FS is replaced by 2*PI.

Spectrogram (...) When the function is called without an output parameter, the PSD estimate for each segment is automatically drawn, and the command is drawn as follows

Surf (T,F,10*LOG10 (ABS (P)));

Axis tight;

View (0,90);

Spectrogram (..., ' freqloc ') uses the Freqloc string to control the position of the frequency axis display. When Freqloc=xaxis

, the frequency axis is displayed on the x-axis, and when Freqloc=yaxis, the frequency axis is displayed on the y-axis, which is displayed by default on the x-axis

On If the freqloc is specified with an output variable, then Freqloc will be ignored. 3. Example

For example, the PSD plot for two sweep signals is calculated and displayed, and the frequency of the sweep signal starts at 100Hz and 200Hz at 1s.

T = 0:0.001:2;
X = chirp (t,100,1,200, ' Q ');
Spectrogram (X,128,120,128,1E3);
Title (' Quadratic Chirp ');

For example, the PSD diagram of a linear sweep signal is calculated and displayed, the sweep signal is started by DC, and at 1s, the control frequency axis is displayed on the Y axis.

T = 0:0.001:2;
X = Chirp (t,0,1,150);
[S,f,t,p] = Spectrogram (X,256,250,256,1E3);
Surf (T,F,10*LOG10 (P), ' Edgecolor ', ' none '); Axis tight;
View (0,90);
Xlabel (' Time (Seconds) '); Ylabel (' Hz ');

4. precautions

The larger the NFFT, the higher the resolution of the frequency domain (resolution =FS/NFFT), but the farther away from the instantaneous frequency;

Noverlap affect the resolution of the time axis, the closer to Nfft, the higher the resolution, the more redundant the corresponding, the greater the computational capacity, but the computer as long as can bear, the problem is not big.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.