www.gusucode.com > signal 案例源码程序 matlab代码 > signal/SpectrogramWithThresholdExample.m

    %% Spectrogram with Threshold
% Generate a chirp signal sampled for 2 seconds at 1 kHz.  Specify the
% chirp so that its frequency is initially 100 Hz and increases to 200 Hz
% after 1 second.

% Copyright 2015 The MathWorks, Inc.


%%

Fs = 1000;
t = 0:1/Fs:2;
y = chirp(t,100,1,200,'quadratic');

%%
% Estimate the time-dependent power spectral density (PSD) of the signal.
%
% * Divide the signal into sections of length 128, windowed with a Kaiser
% window with shape parameter $\beta=18$.
% * Specify 120 samples of overlap between adjoining sections.
% * Evaluate the spectrum at $\lfloor128/2\rfloor=65$ frequencies and
% $\lfloor({\tt length(x)}-120)/(128-120)\rfloor=235$ time bins.
%
% Output the frequency and time of the center of gravity of each PSD
% estimate. Set to zero those elements of the PSD smaller than $-30$ dB.

[~,~,~,pxx,fc,tc] = spectrogram(y,kaiser(128,18),120,128,Fs, ...
    'MinThreshold',-30);


%%
% Plot the nonzero elements as functions of the center-of-gravity
% frequencies and times.

plot(tc(pxx>0),fc(pxx>0),'.')