Documente Academic
Documente Profesional
Documente Cultură
ConstantFalseAlarmRate(CFAR)Detection
Thisexampleintroducesconstantfalsealarmrate(CFAR)detectionand
showshowtouseCFARDetectorandCFARDetector2DinthePhasedArray OpenScript
SystemToolboxtoperformcellaveragingCFARdetection.
Introduction
Oneimportanttaskaradarsystemperformsistargetdetection.Thedetectionitselfisfairlystraightforward.Itcompares
thesignaltoathreshold.Therefore,therealworkondetectioniscomingupwithanappropriatethreshold.Ingeneral,the
thresholdisafunctionofboththeprobabilityofdetectionandtheprobabilityoffalsealarm.
Inmanyphasedarraysystems,becauseofthecostassociatedwithafalsedetection,itisdesirabletohaveadetection
thresholdthatnotonlymaximizestheprobabilityofdetectionbutalsokeepstheprobabilityoffalsealarmbelowapreset
level.
Thereisextensiveliteratureonhowtodeterminethedetectionthreshold.ReadersmightbeinterestedintheSignal
DetectioninWhiteGaussianNoiseandSignalDetectionUsingMultipleSamplesexamplesforsomewellknownresults.
However,alltheseclassicalresultsarebasedontheoreticalprobabilitiesandarelimitedtowhiteGaussiannoisewith
knownvariance(power).Inrealapplications,thenoiseisoftencoloredanditspowerisunknown.
CFARtechnologyaddressestheseissues.InCFAR,whenthedetectionisneededforagivencell,oftentermedasthe
cellundertest(CUT),thenoisepowerisestimatedfromneighboringcells.Thenthedetectionthreshold, ,isgivenby
Fromtheequation,itisclearthatthethresholdadaptstothedata.Itcanbeshownthatwiththeappropriatethreshold
factor, ,theresultingprobabilityoffalsealarmcanbekeptataconstant,hencethenameCFAR.
CellAveragingCFARDetection
ThecellaveragingCFARdetectorisprobablythemostwidelyusedCFARdetector.Itisalsousedasabaseline
comparisonforotherCFARtechniques.InacellaveragingCFARdetector,noisesamplesareextractedfrombothleading
andlaggingcells(calledtrainingcells)aroundtheCUT.Thenoiseestimatecanbecomputedas[1]
Thefollowingfigureshowstherelationamongthesecellsforthe1Dcase.
https://www.mathworks.com/help/phased/examples/constantfalsealarmratecfardetection.html 1/8
2/19/2017 ConstantFalseAlarmRate(CFAR)DetectionMATLAB&SimulinkExample
WiththeabovecellaveragingCFARdetector,assumingthedatapassedintothedetectorisfromasinglepulse,i.e.,no
pulseintegrationinvolved,thethresholdfactorcanbewrittenas[1]
where isthedesiredfalsealarmrate.
CFARDetectionUsingAutomaticThresholdFactor
Intherestofthisexample,weshowhowtousePhasedArraySystemToolboxtoperformacellaveragingCFAR
detection.Forsimplicityandwithoutlosinganygenerality,westillassumethatthenoiseiswhiteGaussian.Thisenables
thecomparisonbetweentheCFARandclassicaldetectiontheory.
WecaninstantiateaCFARdetectorusingthefollowingcommand
cfar=phased.CFARDetector('NumTrainingCells',20,'NumGuardCells',2);
Inthisdetectorweuse20trainingcellsand2guardcellsintotal.Thismeansthatthereare10trainingcellsand1guard
celloneachsideoftheCUT.Asmentionedabove,ifweassumethatthesignalisfromasquarelawdetectorwithno
pulseintegration,thethresholdcanbecalculatedbasedonthenumberoftrainingcellsandthedesiredprobabilityoffalse
alarm.Assumingthedesiredfalsealarmrateis0.001,wecanconfiguretheCFARdetectorasfollowssothatthis
calculationcanbecarriedout.
exp_pfa=1e3;
cfar.ThresholdFactor='Auto';
cfar.ProbabilityFalseAlarm=exp_pfa;
TheconfiguredCFARdetectorisshownbelow.
cfar
cfar=
phased.CFARDetectorwithproperties:
Method:'CA'
NumGuardCells:2
NumTrainingCells:20
ThresholdFactor:'Auto'
ProbabilityFalseAlarm:1.0000e03
ThresholdOutputPort:false
Wenowsimulatetheinputdata.SincethefocusistoshowthattheCFARdetectorcankeepthefalsealarmrateundera
certainvalue,wejustsimulatethenoisesamplesinthosecells.Herearethesettings:
https://www.mathworks.com/help/phased/examples/constantfalsealarmratecfardetection.html 2/8
2/19/2017 ConstantFalseAlarmRate(CFAR)DetectionMATLAB&SimulinkExample
Thedatasequenceis23sampleslong,andtheCUTiscell12.Thisleaves10trainingcellsand1guardcelloneach
sideoftheCUT.
Thefalsealarmrateiscalculatedusing100thousandMonteCarlotrials
rs=RandStream('mt19937ar','Seed',2010);
npower=db2pow(10);%Assume10dBSNRratio
Ntrials=1e5;
Ncells=23;
CUTIdx=12;
%Noisesamplesafterasquarelawdetector
rsamp=randn(rs,Ncells,Ntrials)+1i*randn(rs,Ncells,Ntrials);
x=abs(sqrt(npower/2)*rsamp).^2;
Toperformthedetection,passthedatathroughthedetector.Inthisexample,thereisonlyoneCUT,sotheoutputisa
logicalvectorcontainingthedetectionresultforallthetrials.Iftheresultistrue,itmeansthatatargetispresentinthe
correspondingtrial.Inourexample,alldetectionsarefalsealarmsbecauseweareonlypassinginnoise.Theresulting
falsealarmratecanthenbecalculatedbasedonthenumberoffalsealarmsandthenumberoftrials.
x_detected=cfar(x,CUTIdx);
act_pfa=sum(x_detected)/Ntrials
act_pfa=
9.4000e04
Theresultshowsthattheresultingprobabilityoffalsealarmisbelow0.001,justaswespecified.
CFARDetectionUsingCustomThresholdFactor
Asexplainedintheearlierpartofthisexample,thereareonlyafewcasesinwhichtheCFARdetectorcanautomatically
computetheappropriatethresholdfactor.Forexample,usingthepreviousscenario,ifweemploya10pulsesnoncoherent
integrationbeforethedatagoesintothedetector,theautomaticthresholdcannolongerprovidethedesiredfalsealarm
rate.
npower=db2pow(10);%Assume10dBSNRratio
xn=0;
form=1:10
rsamp=randn(rs,Ncells,Ntrials)+1i*randn(rs,Ncells,Ntrials);
xn=xn+abs(sqrt(npower/2)*rsamp).^2;%noncoherentintegration
end
x_detected=cfar(xn,CUTIdx);
act_pfa=sum(x_detected)/Ntrials
act_pfa=
Onemaybepuzzledwhywethinkaresultingfalsealarmrateof0isworsethanafalsealarmrateof0.001.Afterall,isn't
afalsealarmrateof0agreatthing?Theanswertothisquestionliesinthefactthatwhentheprobabilityoffalsealarmis
decreased,soistheprobabilityofdetection.Inthiscase,becausethetruefalsealarmrateisfarbelowtheallowedvalue,
thedetectionthresholdissettoohigh.Thesameprobabilityofdetectioncanbeachievedwithourdesiredprobabilityof
falsealarmatlowercostforexample,withlowertransmitterpower.
https://www.mathworks.com/help/phased/examples/constantfalsealarmratecfardetection.html 3/8
2/19/2017 ConstantFalseAlarmRate(CFAR)DetectionMATLAB&SimulinkExample
Inmostcases,thethresholdfactorneedstobeestimatedbasedonthespecificenvironmentandsystemconfiguration.
WecanconfiguretheCFARdetectortouseacustomthresholdfactor,asshownbelow.
release(cfar);
cfar.ThresholdFactor='Custom';
Continuingwiththepulseintegrationexampleandusingempiricaldata,wefoundthatwecanuseacustomthreshold
factorof2.35toachievethedesiredfalsealarmrate.Usingthisthreshold,weseethattheresultingfalsealarmrate
matchestheexpectedvalue.
cfar.CustomThresholdFactor=2.35;
x_detected=cfar(xn,CUTIdx);
act_pfa=sum(x_detected)/Ntrials
act_pfa=
9.6000e04
CFARDetectionThreshold
ACFARdetectionoccurswhentheinputsignallevelinacellexceedsthethresholdlevel.Thethresholdlevelforeach
celldependsonthethresholdfactorandthenoisepowerinthatderivedfromtrainingcells.Tomaintainaconstantfalse
alarmrate,thedetectionthresholdwillincreaseordecreaseinproportiontothenoisepowerinthetrainingcells.Configure
theCFARdetectortooutputthethresholdusedforeachdetectionusingtheThresholdOutputPortproperty.Usean
automaticthresholdfactorand200trainingcells.
release(cfar);
cfar.ThresholdOutputPort=true;
cfar.ThresholdFactor='Auto';
cfar.NumTrainingCells=200;
Next,createasquarelawinputsignalwithincreasingnoisepower.
rs=RandStream('mt19937ar','Seed',2010);
Npoints=1e4;
rsamp=randn(rs,Npoints,1)+1i*randn(rs,Npoints,1);
ramp=linspace(1,10,Npoints)';
xRamp=abs(sqrt(npower*ramp./2).*rsamp).^2;
Computedetectionsandthresholdsforallcellsinthesignal.
[x_detected,th]=cfar(xRamp,1:length(xRamp));
Next,comparetheCFARthresholdtotheinputsignal.
plot(1:length(xRamp),xRamp,1:length(xRamp),th,...
find(x_detected),xRamp(x_detected),'o')
legend('Signal','Threshold','Detections','Location','Northwest')
xlabel('TimeIndex')
ylabel('Level')
https://www.mathworks.com/help/phased/examples/constantfalsealarmratecfardetection.html 4/8
2/19/2017 ConstantFalseAlarmRate(CFAR)DetectionMATLAB&SimulinkExample
Here,thethresholdincreaseswiththenoisepowerofthesignaltomaintaintheconstantfalsealarmrate.Detections
occurwherethesignallevelexceedsthethreshold.
ComparisonBetweenCFARandClassicalNeymanPearsonDetector
Inthissection,wecomparetheperformanceofaCFARdetectorwiththeclassicaldetectiontheoryusingtheNeyman
Pearsonprinciple.Returningtothefirstexampleandassumingthetruenoisepowerisknown,thetheoreticalthreshold
canbecalculatedas
T_ideal=npower*db2pow(npwgnthresh(exp_pfa));
ThefalsealarmrateofthisclassicalNeymanPearsondetectorcanbecalculatedusingthistheoreticalthreshold.
act_Pfa_np=sum(x(CUTIdx,:)>T_ideal)/Ntrials
act_Pfa_np=
9.5000e04
Becauseweknowthenoisepower,classicaldetectiontheoryalsoproducesthedesiredfalsealarmrate.Thefalsealarm
rateachievedbytheCFARdetectorissimilar.
release(cfar);
cfar.ThresholdOutputPort=false;
cfar.NumTrainingCells=20;
x_detected=cfar(x,CUTIdx);
act_pfa=sum(x_detected)/Ntrials
act_pfa=
9.4000e04
https://www.mathworks.com/help/phased/examples/constantfalsealarmratecfardetection.html 5/8
2/19/2017 ConstantFalseAlarmRate(CFAR)DetectionMATLAB&SimulinkExample
Next,assumethatbothdetectorsaredeployedtothefieldandthatthenoisepoweris1dBmorethanexpected.Inthis
case,ifweusethetheoreticalthreshold,theresultingprobabilityoffalsealarmisfourtimesmorethanwhatwedesire.
npower=db2pow(9);%Assume9dBSNRratio
rsamp=randn(rs,Ncells,Ntrials)+1i*randn(rs,Ncells,Ntrials);
x=abs(sqrt(npower/2)*rsamp).^2;
act_Pfa_np=sum(x(CUTIdx,:)>T_ideal)/Ntrials
act_Pfa_np=
0.0041
Onthecontrary,theCFARdetector'sperformanceisnotaffected.
x_detected=cfar(x,CUTIdx);
act_pfa=sum(x_detected)/Ntrials
act_pfa=
0.0011
Hence,theCFARdetectorisrobusttonoisepoweruncertaintyandbettersuitedtofieldapplications.
Finally,useaCFARdetectioninthepresenceofcolorednoise.Wefirstapplytheclassicaldetectionthresholdtothe
data.
npower=db2pow(10);
fcoeff=maxflat(10,'sym',0.2);
x=abs(sqrt(npower/2)*filter(fcoeff,1,rsamp)).^2;%colorednoise
act_Pfa_np=sum(x(CUTIdx,:)>T_ideal)/Ntrials
act_Pfa_np=
Notethattheresultingfalsealarmratecannotmeettherequirement.However,usingtheCFARdetectorwithacustom
thresholdfactor,wecanobtainthedesiredfalsealarmrate.
release(cfar);
cfar.ThresholdFactor='Custom';
cfar.CustomThresholdFactor=12.85;
x_detected=cfar(x,CUTIdx);
act_pfa=sum(x_detected)/Ntrials
act_pfa=
0.0010
CFARDetectionForRangeDopplerImages
Intheprevioussections,thenoiseestimatewascomputedfromtrainingcellsleadingandlaggingtheCUTinasingle
dimension.WecanalsoperformCFARdetectiononimages.Cellscorrespondtopixelsintheimages,andguardcellsand
trainingcellsareplacedinbandsaroundtheCUT.Thedetectionthresholdiscomputedfromcellsintherectangular
trainingbandaroundtheCUT.
https://www.mathworks.com/help/phased/examples/constantfalsealarmratecfardetection.html 6/8
2/19/2017 ConstantFalseAlarmRate(CFAR)DetectionMATLAB&SimulinkExample
Inthefigureabove,theguardbandsizeis[22]andthetrainingbandsizeis[43].Thesizeindicesrefertothenumberof
cellsoneachsideoftheCUTintherowandcolumnsdimensions,respectively.Theguardbandsizecanalsobedefined
as2,sincethesizeisthesamealongrowandcolumndimensions.
Next,createatwodimensionalCFARdetector.Useaprobabilityoffalsealarmof1e5andspecifyaguardbandsizeof5
cellsandatrainingbandsizeof10cells.
cfar2D=phased.CFARDetector2D('GuardBandSize',5,'TrainingBandSize',10,...
'ProbabilityFalseAlarm',1e5);
Next,loadandplotarangedopplerimage.Theimageincludesreturnsfromtwostationarytargetsandonetargetmoving
awayfromtheradar.
[resp,rngGrid,dopGrid]=helperRangeDoppler;
UseCFARtosearchtherangedopplerspaceforobjects,andplotamapofthedetections.Searchfrom10to10kHzand
from1000to4000m.First,definethecellsundertestforthisregion.
[~,rangeIndx]=min(abs(rngGrid[10004000]));
[~,dopplerIndx]=min(abs(dopGrid[1e41e4]));
https://www.mathworks.com/help/phased/examples/constantfalsealarmratecfardetection.html 7/8
2/19/2017 ConstantFalseAlarmRate(CFAR)DetectionMATLAB&SimulinkExample
[columnInds,rowInds]=meshgrid(dopplerIndx(1):dopplerIndx(2),...
rangeIndx(1):rangeIndx(2));
CUTIdx=[rowInds(:)columnInds(:)]';
Computeadetectionresultforeachcellundertest.Eachpixelinthesearchregionisacellinthisexample.Plotamapof
thedetectionresultsfortherangedopplerimage.
detections=cfar2D(resp,CUTIdx);
helperDetectionsMap(resp,rngGrid,dopGrid,rangeIndx,dopplerIndx,detections)
Thethreeobjectsaredetected.Adatacubeofrangedopplerimagesovertimecanlikewisebeprovidedastheinput
signaltocfar2D,anddetectionswillbecalculatedinasinglestep.
Summary
Inthisexample,wepresentedthebasicconceptsbehindCFARdetectors.Inparticular,weexploredhowtousethe
PhasedArraySystemToolboxtoperformcellaveragingCFARdetectiononsignalsandrangedopplerimages.The
comparisonbetweentheperformanceofferedbyacellaveragingCFARdetectorandadetectorequippedwiththe
theoreticallycalculatedthresholdshowsclearlythattheCFARdetectorismoresuitableforrealfieldapplications.
Reference
[1]MarkRichards,FundamentalsofRadarSignalProcessing,McGrawHill,2005
https://www.mathworks.com/help/phased/examples/constantfalsealarmratecfardetection.html 8/8