介绍
本程序为论文《基于LFMCW雷达多目标检测的CA-CFAR改进算法》的MATLAB仿真。
数据为自己生成的数据,和论文中的应用场景不太一样,所以出来的效果一般。
论文链接:https://doi.org/10.3788/LOP202158.0815005
仿真实现
使用的数据
为了好看加了换行,在输入matlab时请自行将所有换行去掉,或者在所有换行后面加...
。
testCurve = [
-4.00046072249241,-4.00916612424503,-3.99868073559450,-3.97561176289464,
-3.99752741051632,-3.96371614790865,-3.98246399613047,-3.95149074618515,
-3.95618483562993,-3.94575629397935,-3.93997199804566,-3.93020334064069,
-3.91054340635897,-3.90407319185731,-3.88722216218167,-3.86971862402075,
-3.84458505787318,-3.83661829783082,-3.82811048074754,-3.80763004536850,
-3.78187600105391,-3.76414082913886,-3.73130935778675,-3.69669796571596,
-3.65980073711343,-3.62147002260979,-3.55475008559481,-3.47498896735810,
-3.35456119017322,-3.12760126365172,-2.63983408947976,-1.85853992192638,
-2.64999924904509,-3.15480485951190,-3.44939814957582,-3.62296909218383,
-3.70457184661136,-3.72242957199896,-3.71403045645065,-3.66553182812726,
-3.61235213140046,-3.53824479089210,-3.46062421912936,-3.35744712351894,
-3.22913191588586,-3.05802583712110,-2.81531044575637,-2.49451745625283,
-2.16337684419068,-2.03765527893405,-2.16204425351100,-2.46880439026417,
-2.74636778791327,-2.92187315376571,-3.00369761595957,-3.01496180203514,
-2.96896246925909,-2.85962040433090,-2.67365945097514,-2.42149853118244,
-2.17418741447772,-2.07541672421437,-2.20528174217008,-2.50394624420304,
-2.77023177101778,-2.95327304190220,-3.07518895023388,-3.16117581125846,
-3.22340914628381,-3.27035912246685,-3.30196348212411,-3.31874138889526,
-3.32902809531113,-3.31671940806936,-3.29289121046629,-3.24414742848566,
-3.14914183677004,-2.97492573067891,-2.60838272322183,-1.86379766465966,
-2.64752978129537,-3.10433840101155,-3.33128171970064,-3.48174671592690,
-3.57991099147322,-3.65132436210858,-3.71360093037467,-3.76285943460084,
-3.78972766723271,-3.84101088802099,-3.84843667207511,-3.87180454220423,
-3.89361454955389,-3.90928648601503,-3.91932373656685,-3.92400260000978,
-3.94678294471720,-3.95695890069538,-3.97430340780361,-3.97173782130937,
-3.97502047293826,-3.99450422679268,-4.01088369788039,-4.00603436202738,
-3.99581241115918,-4.00725571710707,-4.00309449192999,-3.99524028631468,
-4.01942705140534,-4.03032990308350,-4.01360299131726,-4.02387372883643,
-4.02797436411055,-4.01405362168534,-4.04479877725247,-4.04517582952763,
-4.02164017383048,-4.02271707879457,-4.02209256193725,-4.02811237999705,
-4.01575382898720,-4.00400715933476,-4.01577051888860,-4.02291029374845,
-4.01671034545974,-4.01023405196569,-4.02063531757798,-4.01031382654274
]
仿真本体
%% An Implementation of improved CA-CFAR Algorithm
% webpage of the implemated paper doi.org/10.3788/LOP202158.0815005
% copyright xuyuntao 2022
%% clear workspace
clc;
close all;
clearvars;
%% parameters (editable)
Pfa = 0.01; % 虚警概率
guardCellsNum = 2; % 保护单元个数
trainCellsNum = 4; % 参考单元个数
subsectionNums = 2; % 二等分
IfAddNoise = true; % 是否添加噪声
noiseMu = 1; % 指数分布中的mu参数,对应本文式2中lambda
requestSNR = 10; % 指定信噪比
% 这里需要验证是否可以二等分,不可以的话暂时考虑报错
decreaseFactor = 1; % 原文中1/p,式13、14
%% variables (do not edit)
thresholdFactor = (Pfa)^(-1/(2*trainCellsNum)) - 1; % 根据虚警率计算门限系数,式9
if (subsectionNums <= 0) && (mod(subsectionNums,1) ~= 0)
error(message('请确保参数 subsectionNums 为大于零的整数'));
end
if (mod((trainCellsNum/subsectionNums),1)~= 0)
error(message('请确保参数 trainCellsNum 可被参数 subsectionNums 整除'));
end
if ((decreaseFactor <=0) && (decreaseFactor > 1))
error(message('请确保参数 decreaseFactor 属于 (0,1] 区间内'));
end
%% load data
% load('testCurve.mat','testCurve'); % 这里请用上面的数据替换之
data = reshape(testCurve,1,[]); % 下面对data进行检测,需要确保data为一维的
data = data - min(data); % 将最小值变换到0方便看
dataLen = length(data); % 一维数据长度,提出来方便写程序
detectDataLen = dataLen - (guardCellsNum + trainCellsNum) * 2; % 需要处理的数据长度
%% adding noise
if IfAddNoise
noise = exprnd(noiseMu,size(data));
signalPow = mean(abs(data).^2,'all');
noisePow = mean(abs(noise).^2,'all');
snrPow = db2pow(requestSNR);
reqNoisePow = signalPow / snrPow;
noiseFactor = reqNoisePow / noisePow;
noise = sqrt(noiseFactor) * noise;
data = data + noise;
end
%% data processing
detectIndex = zeros([1,detectDataLen]); % 所有检测单元的索引
detectLeftSection = zeros([detectDataLen,trainCellsNum]); % 检测单元左侧的参考单元数据
detectRightSection = zeros([detectDataLen,trainCellsNum]); % 检测单元右侧的参考单元数据
indexTmp = 1;
for dataIndex = (guardCellsNum + trainCellsNum + 1):(dataLen - guardCellsNum - trainCellsNum)
detectIndex(1,indexTmp) = dataIndex;
detectLeftSection(indexTmp,:) = data(1,(dataIndex - guardCellsNum - trainCellsNum):(dataIndex - guardCellsNum - 1));
detectRightSection(indexTmp,:) = data(1,(dataIndex + guardCellsNum + 1):(dataIndex + guardCellsNum + trainCellsNum));
indexTmp = indexTmp + 1;
end
sectionAvg = (sum(detectLeftSection, 2) + sum(detectRightSection, 2)) / (trainCellsNum * 2); % 参考单元均值,原文Z
detectLeftSubsection = reshape(detectLeftSection.',[],size(detectLeftSection,1)*subsectionNums).'; % 左等分子单元
detectRightSubsection = reshape(detectRightSection.',[],size(detectRightSection,1)*subsectionNums).'; % 右等分子单元
detectLeftSubsectionMean = mean(detectLeftSubsection,2); % 左等分子单元平均,式12
detectRightSubsectionMean = mean(detectRightSubsection,2); % 右等分子单元平均,式12
sectionAvgTmp = repelem(sectionAvg,subsectionNums); % 重复以匹配子单元等分
unmatchLeftSubsection = (detectLeftSubsectionMean > sectionAvgTmp); % 式13大于Z者
unmatchRightSubsection = (detectRightSubsectionMean > sectionAvgTmp); % 式14大于Z者
detectLeftSubsectionMean(unmatchLeftSubsection) = sectionAvgTmp(unmatchLeftSubsection) * decreaseFactor; % 式13,修改为1/p
detectRightSubsectionMean(unmatchRightSubsection) = sectionAvgTmp(unmatchRightSubsection) * decreaseFactor; % 式14,修改为1/p
detectLeftSubsectionMeanFinal = reshape(detectLeftSubsectionMean.',subsectionNums,[]).';
detectRightSubsectionMeanFinal = reshape(detectRightSubsectionMean.',subsectionNums,[]).';
sectionAvgFinal = (sum(detectLeftSubsectionMeanFinal,2) + sum(detectRightSubsectionMeanFinal,2)) / (subsectionNums * 2);
%% plot
f1 = figure(1);
plot(1:dataLen,log10(data));
hold on;
plot(detectIndex,log10(sectionAvgFinal));
plot(detectIndex,log10(sectionAvg),'--');
hold off;
legend('原始数据','改进CA-CFAR的检测门限','CA-CFAR的检测门限');
close(f1);
f1 = figure(2);
plot(1:dataLen,(data));
hold on;
plot(detectIndex,(sectionAvgFinal));
plot(detectIndex,(sectionAvg),'--');
hold off;
legend('原始数据','改进CA-CFAR的检测门限','CA-CFAR的检测门限');
% close(f2);