You are on page 1of 16

Spectrum Estimation

W. Rose 2013-04-06

Department of Kinesiology and Applied Physiology

Signalx(t)t=0toT
T=samplinginterval=1/fsamp
N=numberofsamples
T=NT
Simplespectrumestimate
S(f)=powerspectrum=k||X(f)||2
X(f)=discreteFouriertransformofx(t)(X(f)iscomplex)
where f=0tofN/2=0tofsamp/2(singlesided)
f=0tof(N1)(twosided)
andwhere
f=1/T

Department of Kinesiology and Applied Physiology

SpectrumDetails
S(f)=powerspectrum=k||X(f)||2
where X(f)=discreteFouriertransformofx(t)
X(f)iscomplex;S(f)isreal
If x(t)hasNpoints
Then twosidedspectrumhasNpoints
onesidedspectrumhasN/2+1points
k=normalizingfactor;dependsonparticularroutineusedtocalculate
spectrum:singleordoublesided,peakorRMSunits,etc.(1)

Department of Kinesiology and Applied Physiology

Exampleofthesimplespectrumestimate

Suppose
where
f=1,d1=4/,d3=4/(3).424,d5=4/(5).255.
Thismeansx(t)iscomprisedofsinusoidalcomponentswith
frequenciesof1,3,and5Hz,withamplitudesgivenbyd1,d3,
andd5.*
Supposealsothatthesamplingrateisfsamp=100Hz,i.e.
dT=1/fsamp=0.01s,andsupposethatwecollectdatafor5
seconds(Ttotal=5s).
*dk=4/(k)=amplitudesfor1Vsquarewave(kodd).
Department of Kinesiology and Applied Physiology

Exampleofthesimplespectrumestimate
Matlabcodetomaketandx(t)andplot:
dt=0.01
t=(0:499)*dt;
f=1;
d1=4/pi;
d3=4/(3*pi);
d5=4/(5*pi);
x=d1*sin(2*pi*f*t)
+d3*sin(2*pi*3*f*t)
+d5*sin(2*pi*5*f*t);
plot(t,x,.r-);

Department of Kinesiology and Applied Physiology

Exampleofthesimplespectrumestimate
Matlabcodetocomputeamplitudespectrumusingfft(x):
X=fft(x);
Xamp_2s=abs(X);
N=length(x);
T=N*dt;
df=1/T;
freqs=(0:N-1)*df;
plot(freqs,Xamp_2s,.r-);

Note:fft(x)returnsa
2sidedspectrum,as
isevidentfromthe
graphbelow.

Amplitudespectrum
(twosided)

Department of Kinesiology and Applied Physiology

Exampleofthesimplespectrumestimate
Thenonzerovalues|X(f)|=dkN/2,wheredk=theamplitudeof
thesinusoidusedtocontructx(t),asshownonanearlierslide.
Thisshowsthatvaluesreturnedbyfft(x)scalelikeN/2,except
atf=0andf=fNyquist=fsamp/2,atwhichfrequenciesthevalues
returnedbyfft(x)scalelikeN(notshowninthisexample).
Thedividebytwoscalefactorisduetothefactthatthe
energythatstartedoutat1Hzissplitbetween1Hzand99Hz
inthetwosidedspectrum.
Amplitudespectrum
(twosided)

Department of Kinesiology and Applied Physiology

Exampleofthesimplespectrumestimate
Computethesinglesidedpowerspectrum.DividebyNatf=0and
f=fNyquist;dividebyN/2atallotherfrequencies.
S=([Xamp_2s(1) Xamp_2s(2:N/2)*2 Xamp_2s(N/2+1)]/N).^2;
freq1s=(0:N/2)*df;
plot(freq1s,S,'.r-');
xlabel('Frequency (Hz)'); ylabel('Power');

This gives S(f)=d12,d32,d52 at the appropriate frequencies.

Singlesidedpowerspectrum

Department of Kinesiology and Applied Physiology

ABetterSpectrumEstimate
Overview
1.Dividethetimedomainrecordintoblocks.
2.Findpowerspectrumofeachblock.
3.Averagethepowerspectra,frequencybyfrequency.

Department of Kinesiology and Applied Physiology

ABetterSpectrumEstimate:Details
1. Dividetimedomainrecordintosegmentsofequal
length.Ifthereareqnonoverlappingsegments,then
alsoincludeq1halfoverlappedsegments.
Example:Totaldatarecordlength=Ntot=4000points.
Investigatorchoosesq=4.Theneachsegmenthas
lengthNseg=Ntot/q=1000points.Thefournon
overlappingblocksstartatpoints0,1000,2000,3000.
Threehalfoverlappedblocksstartat500,1500,2500.
Totalnumberofsegments=2q1=7.

Department of Kinesiology and Applied Physiology

ABetterSpectrumEstimate:Details
2.Findpowerspectrumofeachsegment.
Beforecomputingspectrumofeachsegment,remove
lineartrend,resultinginblockwithzeromeanvalue
andzeroslope.Someprefertoremoveonlythemean
valueandnotthelineartrend(ifany).
WindowthedatainthesegmentwithHannor
Hammingwindow.
Computepowerspectrumofwindoweddata.
Correctpowerspectrumforthelossofpowercaused
bythewindow:
Hannwindow:multiplypowerestimatesby8/3.
Hamming:multiplypowerestimatesby2.516.
Department of Kinesiology and Applied Physiology

ABetterSpectrumEstimate:Details
3. Averagethepowerspectra,frequencybyfrequency.
Savg(f)=(1/(2q1))*Sum(i=1to2q1){Si(f)}
whereSi(f)=poweratfrequencyfoftheithsegment

Department of Kinesiology and Applied Physiology

Department of Kinesiology and Applied Physiology

ScaleFactorsforPowerSpectrumEstimates
singlesidedspectrum:Ateachnonzerofrequency(fromfto
highestfrequencybelowthehalfwaypoint,whichisf=f samp/2),
multiplythetwosidedestimateatthatfrequencyby2togetthesingle
sidedpowerestimate.Thesinglesidedspectrumonlygoestof samp/2.At
f=0andatf=fsamp/2,thesinglesidedestimateisthesameasthetwo
sidedestimate.
SeeLabviewhelpforPowerSpectrum.vi(returnstwosidedspectrum)
andAutoPowerSpectrum.vi.(returnsonesidedspectrum).

Department of Kinesiology and Applied Physiology

RMS units

Some routines, such as Labviews AutoPowerSpectrum.vi, give S(f) in root


mean square units by default. The net effect is to divide the power spectrum
estimate by 2, if f>0, compared to the power spectrum estimate given in peak
units.

Reason: The average power of a signal is defined as

This definition was chosen because it equals the power dissipated in a 1 ohm
resistor by a current I=x(t). If x(t)=Acos(2ft), and if T=a whole number of
cycles, then we can solve the integral to show that P=A2/2 if f>0, and P=A2 if
f=0.
It is called root mean square, because a time-varying signal has much power
as a steady signal whose amplitude equals the square root of the mean of the
squared amplitude of the time varying signal.

Department of Kinesiology and Applied Physiology

PartialfrontpanelofFFT_and_Power_Spectrum_Units.vi
ExampleVIinLV2012

OutputfromFFT.viscaleslikerecordlengthn.OtherVIsreturnoutputwhichhis
independentofrecordlength.FFTandPower_Spectrumreturntwosidedspectra,
whichiswhytheirnonDCscalingisdividedby2.TheotherVIsreturnonesided
spectra.FFT_Power_Spectral_Densitydivideseachpowerspectrumestimateby
f,thefrequencyspacingbetweenestimates(f=spectralwidthofeachestimate).
Department of Kinesiology and Applied Physiology