Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
423 views

Spectrogram Using Short-Time Fourier Transform - MATLAB Spectrogram PDF

This document discusses using the spectrogram function in MATLAB to analyze signals in the time-frequency domain and obtain their short-time Fourier transform (STFT). The spectrogram function returns the STFT of an input signal, with each column containing an estimate of the signal's localized frequency content over short periods of time. The document provides details on the syntax, parameters, and examples of using spectrogram to compute and plot the STFT and spectrogram of various signals like chirps. It also demonstrates how the spectrogram can be used to measure and track the instantaneous frequency of signals over time.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
423 views

Spectrogram Using Short-Time Fourier Transform - MATLAB Spectrogram PDF

This document discusses using the spectrogram function in MATLAB to analyze signals in the time-frequency domain and obtain their short-time Fourier transform (STFT). The spectrogram function returns the STFT of an input signal, with each column containing an estimate of the signal's localized frequency content over short periods of time. The document provides details on the syntax, parameters, and examples of using spectrogram to compute and plot the STFT and spectrogram of various signals like chirps. It also demonstrates how the spectrogram can be used to measure and track the instantaneous frequency of signals over time.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

spectrogram
SpectrogramusingshorttimeFouriertransform

Syntax
s=spectrogram(x)

example

s=spectrogram(x,window)
s=spectrogram(x,window,noverlap)

example

s=spectrogram(x,window,noverlap,nfft)

example

[s,w,t]=spectrogram( ___ )
[s,f,t]=spectrogram( ___ ,fs)

example

[s,w,t]=spectrogram(x,window,noverlap,w)
[s,f,t]=spectrogram(x,window,noverlap,f,fs)
[ ___ ,ps]=spectrogram( ___ )
[ ___ ]=spectrogram( ___ ,'reassigned')

example

[ ___ ,ps,fc,tc]=spectrogram( ___ )

example

[ ___ ]=spectrogram( ___ ,freqrange)


[ ___ ]=spectrogram( ___ ,spectrumtype)
[ ___ ]=spectrogram( ___ ,'MinThreshold',thresh)

example

spectrogram( ___ )

example

spectrogram( ___ ,freqloc)

example

Description
s=spectrogram(x)returnstheshorttimeFouriertransformoftheinputsignal,x.Eachcolumn
ofscontainsanestimateoftheshortterm,timelocalizedfrequencycontentofx.

example

s=spectrogram(x,window)useswindowtodividethesignalintosectionsandperform
windowing.
s=spectrogram(x,window,noverlap)usesnoverlapsamplesofoverlapbetweenadjoining
sections.

example

s=spectrogram(x,window,noverlap,nfft)usesnfftsamplingpointstocalculatethe
discreteFouriertransform.

example

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

1/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

[s,w,t]=spectrogram( ___ )returnsavectorofnormalizedfrequencies,w,andavectoroftime


instants,t,atwhichthespectrogramiscomputed.Thissyntaxcanincludeanycombinationof
inputargumentsfromprevioussyntaxes.
[s,f,t]=spectrogram( ___ ,fs)returnsavectorofcyclicalfrequencies,f,expressedinterms
ofthesamplerate,fs.

example

[s,w,t]=spectrogram(x,window,noverlap,w)returnsthespectrogramatthenormalized
frequenciesspecifiedinw.
[s,f,t]=spectrogram(x,window,noverlap,f,fs)returnsthespectrogramatthecyclical
frequenciesspecifiedinf.
[ ___ ,ps]=spectrogram( ___ )alsoreturnsamatrix,ps,containinganestimateofthepower
spectraldensity(PSD)orthepowerspectrumofeachsection.
[ ___ ]=spectrogram( ___ ,'reassigned')reassignseachPSDorpowerspectrumestimateto
thelocationofitscenterofenergy.Ifyoursignalcontainswelllocalizedtemporalorspectral
components,thenthisoptiongeneratesasharperspectrogram.

example

[ ___ ,ps,fc,tc]=spectrogram( ___ )alsoreturnstwomatrices,fcandtc,containingthe


frequencyandtimeofthecenterofenergyofeachPSDorpowerspectrumestimate.

example

[ ___ ]=spectrogram( ___ ,freqrange)returnsthePSDorpowerspectrumestimateoverthe


frequencyrangespecifiedbyfreqrange.Validoptionsforfreqrangeare'onesided',
'twosided',and'centered'.
[ ___ ]=spectrogram( ___ ,spectrumtype)returnsPSDestimatesifspectrumtypeisspecified
as'psd'andreturnspowerspectrumestimatesifspectrumtypeisspecifiedas'power'.
[ ___ ]=spectrogram( ___ ,'MinThreshold',thresh)setstozerothoseelementsofpssuch
that10log10(ps)thresh.Specifythreshindecibels.

example

spectrogram( ___ )withnooutputargumentsplotsthespectrograminthecurrentfigurewindow.

example

spectrogram( ___ ,freqloc)specifiestheaxisonwhichtoplotthefrequency.

example

Examples

collapseall

DefaultValuesofSpectrogram
Generate
samplesofasignalthatconsistsofasumofsinusoids.The
normalizedfrequenciesofthesinusoidsare
rad/sampleand
rad/sample.The
higherfrequencysinusoidhas10timestheamplitudeoftheothersinusoid.

OpenThisExample

N=1024;
n=0:N1;
w0=2*pi/5;
x=sin(w0*n)+10*sin(2*w0*n);
ComputetheshorttimeFouriertransformusingthefunctiondefaults.Plotthespectrogram.
s=spectrogram(x);
spectrogram(x,'yaxis')
http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

2/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

Repeatthecomputation.

Dividethesignalintosectionsoflength

WindowthesectionsusingaHammingwindow.

Specify50%overlapbetweencontiguoussections.

TocomputetheFFT,use

points,where

Verifythatthetwoapproachesgiveidenticalresults.
Nx=length(x);
nsc=floor(Nx/4.5);
nov=floor(nsc/2);
nff=max(256,2^nextpow2(nsc));
t=spectrogram(x,hamming(nsc),nov,nff);
maxerr=max(abs(abs(t(:))abs(s(:))))
maxerr=
0
Dividethesignalinto8sectionsofequallength,with50%overlapbetweensections.SpecifythesameFFT
lengthasintheprecedingstep.ComputetheshorttimeFouriertransformandverifythatitgivesthesame
resultastheprevioustwoprocedures.

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

3/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

ns=8;
ov=0.5;
lsc=floor(Nx/(ns(ns1)*ov));
t=spectrogram(x,lsc,floor(ov*lsc),nff);
maxerr=max(abs(abs(t(:))abs(s(:))))
maxerr=
0

FrequencyAlongxAxis
Generateaquadraticchirp,x,sampledat1kHzfor2seconds.Thefrequencyofthe
chirpis100Hzinitiallyandcrosses200Hzatt=1s.

OpenThisExample

t=0:0.001:2;
x=chirp(t,100,1,200,'quadratic');
Computeanddisplaythespectrogramofx.

Dividethesignalintosectionsoflength128,windowedwithaHammingwindow.

Specify120samplesofoverlapbetweenadjoiningsections.

Evaluatethespectrumat
timebins.

frequenciesand

spectrogram(x,128,120,128,1e3)

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

4/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

ReplacetheHammingwindowwithaBlackmanwindow.Decreasetheoverlapto60samples.Plotthetime
axissothatitsvaluesincreasefromtoptobottom.
spectrogram(x,blackman(128),60,128,1e3)
ax=gca;
ax.YDir='reverse';

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

5/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

PowerSpectralDensitiesofChirps
ComputeanddisplaythePSDofeachsegmentofaquadraticchirpthatstartsat100Hz
andcrosses200Hzatt=1s.Specifyasamplerateof1kHz,asegmentlengthof128
samples,andanoverlapof120samples.Use128DFTpointsandthedefaultHamming
window.

OpenThisExample

t=0:0.001:2;
x=chirp(t,100,1,200,'quadratic');
spectrogram(x,128,120,128,1e3,'yaxis')
title('QuadraticChirp')

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

6/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

ComputeanddisplaythePSDofeachsegmentofalinearchirpthatstartsatDCandcrosses150Hzatt=1
s.Specifyasamplerateof1kHz,asegmentlengthof256samples,andanoverlapof250samples.Usethe
defaultHammingwindowand256DFTpoints.
t=0:0.001:2;
x=chirp(t,0,1,150);
spectrogram(x,256,250,256,1e3,'yaxis')
title('LinearChirp')

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

7/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

ComputeanddisplaythePSDofeachsegmentofalogarithmicchirpsampledat1kHzthatstartsat20Hz
andcrosses60Hzatt=1s.Specifyasegmentlengthof256samplesandanoverlapof250samples.Use
thedefaultHammingwindowand256DFTpoints.
t=0:0.001:2;
x=chirp(t,20,1,60,'logarithmic');
spectrogram(x,256,250,[],1e3,'yaxis')
title('LogarithmicChirp')

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

8/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

Usealogarithmicscaleforthefrequencyaxis.Thespectrogrambecomesaline.
ax=gca;
ax.YScale='log';

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

9/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

SpectrogramandInstantaneousFrequency
Usethespectrogramfunctiontomeasureandtracktheinstantaneousfrequencyofa
signal.

OpenThisExample

Generateaquadraticchirpsampledat1kHzfortwoseconds.Specifythechirpsothatitsfrequencyisinitially
100Hzandincreasesto200Hzafteronesecond.
Fs=1000;
t=0:1/Fs:21/Fs;
y=chirp(t,100,1,200,'quadratic');
EstimatethespectrumofthechirpusingtheshorttimeFouriertransformimplementedinthespectrogram
function.Dividethesignalintosectionsoflength100,windowedwithaHammingwindow.Specify80samples
ofoverlapbetweenadjoiningsectionsandevaluatethespectrumat
frequencies.Suppress
thedefaultcolorbar.
spectrogram(y,100,80,100,Fs,'yaxis')
view(77,72)
shadinginterp
colorbaroff

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

10/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

Trackthechirpfrequencybyfindingthemaximumofthepowerspectraldensityateachofthe
timepoints.Viewthespectrogramasatwodimensionalgraphic.Restorethe
colorbar.
[s,f,t,p]=spectrogram(y,100,80,100,Fs);
[q,nd]=max(10*log10(p));
holdon
plot3(t,f(nd),q,'r','linewidth',4)
holdoff
colorbar
view(2)

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

11/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

ReassignedSpectrogramofQuadraticChirp
Generateachirpsignalsampledfor2secondsat1kHz.Specifythechirpsothatits
frequencyisinitially100Hzandincreasesto200Hzafter1second.

OpenThisExample

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

Dividethesignalintosectionsoflength128,windowedwithaKaiserwindowwithshapeparameter

Specify120samplesofoverlapbetweenadjoiningsections.

Evaluatethespectrumat
bins.

frequenciesand

.
time

spectrogram(y,kaiser(128,18),120,128,Fs,'reassigned','yaxis')

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

12/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

SpectrogramwithThreshold
Generateachirpsignalsampledfor2secondsat1kHz.Specifythechirpsothatits
frequencyisinitially100Hzandincreasesto200Hzafter1second.

OpenThisExample

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

Dividethesignalintosectionsoflength128,windowedwithaKaiserwindowwithshapeparameter

Specify120samplesofoverlapbetweenadjoiningsections.

Evaluatethespectrumat
bins.

frequenciesand

.
time

OutputthefrequencyandtimeofthecenterofgravityofeachPSDestimate.Settozerothoseelementsof
thePSDsmallerthan
dB.
[~,~,~,pxx,fc,tc]=spectrogram(y,kaiser(128,18),120,128,Fs,...
'MinThreshold',30);
Plotthenonzeroelementsasfunctionsofthecenterofgravityfrequenciesandtimes.
plot(tc(pxx>0),fc(pxx>0),'.')

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

13/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

SpectrogramReassignmentandThresholding
Generateasignalsampledat1024Hzfor2seconds.

OpenThisExample

nSamp=2048;
Fs=1024;
t=(0:nSamp1)'/Fs;
Duringthefirstsecond,thesignalconsistsofa400Hzsinusoidandaconcavequadraticchirp.Specifythe
chirpsothatitissymmetricabouttheintervalmidpoint,startingandendingatafrequencyof250Hzand
attainingaminimumof150Hz.
t1=t(1:nSamp/2);
x11=sin(2*pi*400*t1);
x12=chirp(t1t1(nSamp/4),150,nSamp/Fs,1750,'quadratic');
x1=x11+x12;
Therestofthesignalconsistsoftwolinearchirpsofdecreasingfrequency.Onechirphasaninitialfrequency
of250Hzthatdecreasesto100Hz.Theotherchirphasaninitialfrequencyof400Hzthatdecreasesto250
Hz.

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

14/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

t2=t(nSamp/2+1:nSamp);
x21=chirp(t2,400,nSamp/Fs,100);
x22=chirp(t2,550,nSamp/Fs,250);
x2=x21+x22;
AddwhiteGaussiannoisetothesignal.Specifyasignaltonoiseratioof20dB.Resettherandomnumber
generatorforreproducibleresults.
SNR=20;
rng('default')
sig=[x1;x2];
sig=sig+randn(size(sig))*std(sig)/db2mag(SNR);
Computeandplotthespectrogramofthesignal.SpecifyaKaiserwindowoflength63withashapeparameter
,10fewersamplesofoverlapbetweenadjacentsegments,andanFFTlengthof256.
nwin=63;
wind=kaiser(nwin,17);
nlap=nwin10;
nfft=256;
spectrogram(sig,wind,nlap,nfft,Fs,'yaxis')

ThresholdthespectrogramsothatanyelementswithvaluessmallerthantheSNRaresettozero.
spectrogram(sig,wind,nlap,nfft,Fs,'MinThreshold',SNR,'yaxis')
http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

15/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

ReassigneachPSDestimatetothelocationofitscenterofenergy.
spectrogram(sig,wind,nlap,nfft,Fs,'reassign','yaxis')

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

16/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

ThresholdthereassignedspectrogramsothatanyelementswithvaluessmallerthantheSNRaresettozero.
spectrogram(sig,wind,nlap,nfft,Fs,'reassign','MinThreshold',SNR,'yaxis')

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

17/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

TrackChirpsinAudioSignal
Loadanaudiosignalthatcontainstwodecreasingchirpsandawidebandsplattersound.
ComputetheshorttimeFouriertransform.Dividethewaveforminto400sample
segmentswith300sampleoverlap.Plotthespectrogram.

OpenThisExample

loadsplat
%Tohear,typesoundsc(y,Fs)
sg=400;
ov=300;
spectrogram(y,sg,ov,[],Fs,'yaxis')
colormapbone

Usethespectrogramfunctiontooutputthepowerspectraldensity(PSD)ofthesignal.
[s,f,t,p]=spectrogram(y,sg,ov,[],Fs);
Trackthetwochirpsusingthemedfreqfunction.Tofindthestronger,lowfrequencychirp,restrictthesearch
tofrequenciesabove100Hzandtotimesbeforethestartofthewidebandsound.

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

18/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

f1=f>100;
t1=t<0.75;
m1=medfreq(p(f1,t1),f(f1));
Tofindthefainthighfrequencychirp,restrictthesearchtofrequenciesabove2500Hzandtotimesbetween
0.3secondsand0.65seconds.
f2=f>2500;
t2=t>0.3&t<0.65;
m2=medfreq(p(f2,t2),f(f2));
Overlaytheresultonthespectrogram.Dividethefrequencyvaluesby1000toexpresstheminkHz.
holdon
plot(t(t1),m1/1000,'linewidth',4)
plot(t(t2),m2/1000,'linewidth',4)
holdoff

3DSpectrogramVisualization
Generatetwosecondsofasignalsampledat10kHz.Specifytheinstantaneous
frequencyofthesignalasatriangularfunctionoftime.

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

OpenThisExample

19/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

fs=10e3;
t=0:1/fs:2;
x1=vco(sawtooth(2*pi*t,0.5),[0.10.4]*fs,fs);
Computeandplotthespectrogramofthesignal.UseaKaiserwindowoflength256andshapeparameter
.Specify220samplesofsectiontosectionoverlapand512DFTpoints.Plotthefrequencyonthey
axis.Usethedefaultcolormapandview.
spectrogram(x1,kaiser(256,5),220,512,fs,'yaxis')

Changetheviewtodisplaythespectrogramasawaterfallplot.Setthecolormaptobone.
colormapbone
view(45,65)

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

20/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

RelatedExamples

FormantEstimationwithLPCCoefficients

InputArguments

collapseall

xInputsignal
vector
Inputsignal,specifiedasaroworcolumnvector.
Example:cos(pi/4*(0:159))+randn(1,160)specifiesasinusoidembeddedinwhiteGaussiannoise.
DataTypes:single|double
ComplexNumberSupport:Yes
windowWindow
integer|vector|[]
Window,specifiedasanintegerorasaroworcolumnvector.Usewindowtodividethesignalintosections:

Ifwindowisaninteger,thenspectrogramdividesxintosectionsoflengthwindowandwindowseach
sectionwithaHammingwindowofthatlength.

Ifwindowisavector,thenspectrogramdividesxintosectionsofthesamelengthasthevectorand
windowseachsectionusingwindow.

Ifthelengthofxcannotbedividedexactlyintoanintegernumberofsectionswithnoverlapoverlapping
samples,thenxistruncatedaccordingly.
http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

21/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

Ifyouspecifywindowasempty,thenspectrogramusesaHammingwindowsuchthatxisdividedintoeight
sectionswithnoverlapoverlappingsamples.
Foralistofavailablewindows,seeWindows.
Example:hann(N+1)and(1cos(2*pi*(0:N)'/N))/2bothspecifyaHannwindowoflengthN+1.
DataTypes:single|double
noverlapNumberofoverlappedsamples
positiveinteger|[]
Numberofoverlappedsamples,specifiedasapositiveinteger.

Ifwindowisscalar,thennoverlapmustbesmallerthanwindow.

Ifwindowisavector,thennoverlapmustbesmallerthanthelengthofwindow.

Ifyouspecifynoverlapasempty,thenspectrogramusesanumberthatproduces50%overlapbetween
sections.Ifthesectionlengthisunspecified,thefunctionsetsnoverlaptoNx/4.5,whereNxisthelengthof
theinputsignal.
DataTypes:double|single
nfftNumberofDFTpoints
positiveintegerscalar|[]
NumberofDFTpoints,specifiedasapositiveintegerscalar.Ifyouspecifynfftasempty,thenspectrogram
setstheparametertomax(256,2p),wherep=log2NxforaninputsignaloflengthNx.
DataTypes:single|double
wNormalizedfrequencies
vector
Normalizedfrequencies,specifiedasavector.wmusthaveatleasttwoelements.Normalizedfrequenciesare
inrad/sample.
Example:pi./[24]
DataTypes:double|single
fCyclicalfrequencies
vector
Cyclicalfrequencies,specifiedasavector.fmusthaveatleasttwoelements.Theunitsoffarespecifiedby
thesamplerate,fs.
DataTypes:double|single
fsSamplerate
1Hz(default)|positivescalar
Samplerate,specifiedasapositivescalar.Thesamplerateisthenumberofsamplesperunittime.Iftheunit
oftimeisseconds,thenthesamplingfrequencyisinHz.
http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

22/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

DataTypes:double|single
freqrangeFrequencyrangeforPSDestimate
'onesided'|'twosided'|'centered'
FrequencyrangeforthePSDestimate,specifiedas'onesided','twosided',or'centered'.Forreal
valuedsignals,thedefaultis'onesided'.Forcomplexvaluedsignals,thedefaultis'twosided',and
specifying'onesided'resultsinanerror.

'onesided'returnstheonesidedspectrogramofarealinputsignal.Ifnfftiseven,thenpshaslength
nfft/2+1andiscomputedovertheinterval[0,]rad/sample.Ifnfftisodd,thenpshaslength
(nfft+1)/2andtheintervalis[0,)rad/sample.Ifyouspecifyfs,thentheintervalsarerespectively
[0,fs/2]cycles/unittimeand[0,fs/2)cycles/unittime.

'twosided'returnsthetwosidedspectrogramofarealorcomplexsignal.pshaslengthnfftandis
computedovertheinterval[0,2)rad/sample.Ifyouspecifyfs,thentheintervalis[0,fs)cycles/unit
time.

'centered'returnsthecenteredtwosidedspectrogramforarealorcomplexsignal.pshaslength
nfft.Ifnfftiseven,thenpsiscomputedovertheinterval(,]rad/sample.Ifnfftisodd,thenpsis
computedover(,)rad/sample.Ifyouspecifyfs,thentheintervalsarerespectively
(fs/2,fs/2]cycles/unittimeand(fs/2,fs/2)cycles/unittime.

DataTypes:char
spectrumtypePowerspectrumscaling
'psd'(default)|'power'
Powerspectrumscaling,specifiedas'psd'or'power'.

Omittingspectrumtype,orspecifying'psd',returnsthepowerspectraldensity.

Specifying'power'scaleseachestimateofthePSDbytheequivalentnoisebandwidthofthewindow.
Theresultisanestimateofthepowerateachfrequency.Ifthe'reassigned'optionison,thefunction
integratesthePSDoverthewidthofeachfrequencybinbeforereassigning.

DataTypes:char
threshThreshold
Inf(default)|realscalar
Threshold,specifiedasarealscalarexpressedindecibels.spectrogramsetstozerothoseelementsofps
suchthat10log10(ps)thresh.
freqlocFrequencydisplayaxis
'xaxis'(default)|'yaxis'
Frequencydisplayaxis,specifiedas'xaxis'or'yaxis'.

'xaxis'displaysfrequencyonthexaxisandtimeontheyaxis.

'yaxis'displaysfrequencyontheyaxisandtimeonthexaxis.

Thisargumentisignoredifyoucallspectrogramwithoutputarguments.
DataTypes:char
http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

23/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

OutputArguments

collapseall

sShorttimeFouriertransform
matrix
ShorttimeFouriertransform,returnedasamatrix.Timeincreasesacrossthecolumnsofsandfrequency
increasesdowntherows,startingfromzero.

IfxisasignaloflengthNx,thenshaskcolumns,where

k=(Nxnoverlap)/(windownoverlap)ifwindowisascalar

k=(Nxnoverlap)/(length(window)noverlap)ifwindowisavector.

Ifxisrealandnfftiseven,thenshas(nfft/2+1)rows.

Ifxisrealandnfftisodd,thenshas(nfft+1)/2rows.

Ifxiscomplex,thenshasnfftrows.

DataTypes:double|single
wNormalizedfrequencies
vector
Normalizedfrequencies,returnedasavector.whasalengthequaltothenumberofrowsofs.
DataTypes:double|single
tTimeinstants
vector
Timeinstants,returnedasavector.Thetimevaluesintcorrespondtothemidpointofeachsection.
DataTypes:double|single
fCyclicalfrequencies
vector
Cyclicalfrequencies,returnedasavector.fhasalengthequaltothenumberofrowsofs.
DataTypes:double|single
psPowerspectraldensityorpowerspectrum
matrix
Powerspectraldensity(PSD)orpowerspectrum,returnedasamatrix.

Ifxisreal,thenpscontainstheonesidedmodifiedperiodogramestimateofthePSDorpowerspectrumof
eachsection.

Ifxiscomplex,orifyouspecifyavectoroffrequencies,thenpscontainsthetwosidedmodified
periodogramestimateofthePSDorpowerspectrumofeachsection.

DataTypes:double|single
fc,tcCenterofenergyfrequenciesandtimes
http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

24/25

2/5/2016

SpectrogramusingshorttimeFouriertransformMATLABspectrogram

matrices
Centerofenergyfrequenciesandtimes,returnedasmatricesofthesamesizeastheshorttimeFourier
transform.Ifyoudonotspecifyasamplerate,thentheelementsoffcarereturnedasnormalized
frequencies.

MoreAbout

collapseall

Tips
IfashorttimeFouriertransformhaszeros,itsconversiontodecibelsresultsinnegativeinfinitiesthatcannot
beplotted.Toavoidthispotentialdifficulty,spectrogramaddsepstotheshorttimeFouriertransformwhen
youcallitwithnooutputarguments.

References
[1]Oppenheim,AlanV.,RonaldW.Schafer,andJohnR.Buck.DiscreteTimeSignalProcessing.2ndEd.Upper
SaddleRiver,NJ:PrenticeHall,1999.
[2]Rabiner,LawrenceR.,andRonaldW.Schafer.DigitalProcessingofSpeechSignals.EnglewoodCliffs,NJ:
PrenticeHall,1978.
[3]ChassandeMotin,ric,FranoisAuger,andPatrickFlandrin."Reassignment."InTimeFrequencyAnalysis:
ConceptsandMethods.EditedbyFranzHlawatschandFranoisAuger.London:ISTE/JohnWileyandSons,
2008.
[4]Fulop,SeanA.,andKellyFitz."Algorithmsforcomputingthetimecorrectedinstantaneousfrequency
(reassigned)spectrogram,withapplications."JournaloftheAcousticalSocietyofAmerica.Vol.119,January
2006,pp.360371.

SeeAlso
goertzel|periodogram|pwelch

IntroducedbeforeR2006a

http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

25/25

You might also like