十字CFAR MATLAB仿真代码

% Function     :Cross_CFAR_Processing
% brief        :十字CFAR处理函数
% modification :初始创建,新增雷达十字CFAR功能模块;
function Cross_CFAR_Processing(fft2d_NCI, beamsn)

rd = fft2d_NCI(:, :, beamsn);                                              % beamsn = 1、2分别控制宽、窄波束rd数据(256x256)和宽、窄波束下的BackgroundNoise数据(256x256)调用
[rows, columns] = size(rd);                                                % rows对应doppler最大Idx,columns对应range最大Idx
rd = abs(squeeze(rd));                                                     % 取模值
% BackgroundNoise = bg(:, :, beamsn);
BackgroundNoise = zeros(rows, columns);

GuardCellsNum_Range = 2; GuardCellsNum_Doppler = 2;                        % range、doppler维单侧滑窗的保护单元个数
TrainCellsNum_Range = 4; TrainCellsNum_Doppler = 4;                        % range、doppler维单侧滑窗的的参考单元个数
Train_Left = zeros(rows, columns);                                         % 检测单元左侧参考单元
Train_Right = zeros(rows, columns);                                        % 检测单元右侧参考单元
Train_Up = zeros(rows, columns);                                           % 检测单元上方参考单元
Train_Down = zeros(rows, columns);                                         % 检测单元下方参考单元

for RangeIdx = 1:columns
    if RangeIdx <= GuardCellsNum_Range + 1                                 % 检测单元Idx左侧没有参考单元
        Train_Right(:, RangeIdx) = mean(rd(:, RangeIdx + GuardCellsNum_Range + 1 : RangeIdx + GuardCellsNum_Range + TrainCellsNum_Range), 2);
        Train_Left(:, RangeIdx) = Train_Right(:, RangeIdx);
    elseif (RangeIdx > GuardCellsNum_Range + 1) && (RangeIdx <= GuardCellsNum_Range + TrainCellsNum_Range)                              % 检测单元Idx左侧有参考单元,但个数<TrainCellsNum_Range
        Train_Right(:, RangeIdx) = mean(rd(:, RangeIdx + GuardCellsNum_Range + 1 : RangeIdx + GuardCellsNum_Range + TrainCellsNum_Range), 2);
        Train_Left(:, RangeIdx) = mean(rd(:, 1 : RangeIdx - GuardCellsNum_Range), 2);
    elseif RangeIdx >= columns - GuardCellsNum_Range                       % 检测单元Idx右侧没有参考单元
        Train_Left(:, RangeIdx) = mean(rd(:, RangeIdx - GuardCellsNum_Range - TrainCellsNum_Range : RangeIdx - GuardCellsNum_Range - 1), 2);
        Train_Right(:, RangeIdx) = Train_Left(:, RangeIdx);
    elseif (RangeIdx >= columns - GuardCellsNum_Range - TrainCellsNum_Range + 1) && (RangeIdx < columns - GuardCellsNum_Range)          % 检测单元Idx右侧有参考单元,但个数<TrainCellsNum_Range
        Train_Left(:, RangeIdx) = mean(rd(:, RangeIdx - GuardCellsNum_Range - TrainCellsNum_Range : RangeIdx - GuardCellsNum_Range - 1), 2);
        Train_Right(:, RangeIdx) = mean(rd(:, RangeIdx + GuardCellsNum_Range + 1 : columns), 2);
    else                                                                   % 检测单元Idx左右两侧都有TrainCellsNum_Range个参考单元
        Train_Left(:, RangeIdx) = mean(rd(:, RangeIdx - GuardCellsNum_Range - TrainCellsNum_Range : RangeIdx - GuardCellsNum_Range - 1), 2);
        Train_Right(:, RangeIdx) = mean(rd(:, RangeIdx + GuardCellsNum_Range + 1 : RangeIdx + GuardCellsNum_Range + TrainCellsNum_Range), 2);
    end
    for DopplerIdx = 1:rows
        if DopplerIdx <= GuardCellsNum_Doppler + 1                         % 检测单元Idx上方没有参考单元,取下方对应位置多普勒单元
            Train_Down(DopplerIdx, :) = mean(rd(DopplerIdx + GuardCellsNum_Doppler + 1 : DopplerIdx + GuardCellsNum_Doppler + TrainCellsNum_Doppler, :), 1);
            Train_Up(DopplerIdx, :) = mean(rd(rows - (GuardCellsNum_Doppler - (DopplerIdx - 1)) - TrainCellsNum_Doppler + 1 : rows - (GuardCellsNum_Doppler - (DopplerIdx - 1)), :), 1);
        elseif (DopplerIdx > GuardCellsNum_Doppler + 1) && (DopplerIdx <= GuardCellsNum_Doppler + TrainCellsNum_Doppler)                % 检测单元Idx上方有参考单元,但个数<TrainCellsNum_Doppler
            Train_Down(DopplerIdx, :) = mean(rd(DopplerIdx + GuardCellsNum_Doppler + 1 : DopplerIdx + GuardCellsNum_Doppler + TrainCellsNum_Doppler, :), 1);
            Train_Up(DopplerIdx, :) = mean([rd(rows - (TrainCellsNum_Doppler + GuardCellsNum_Doppler - DopplerIdx) : rows, :); rd(1 : (DopplerIdx - GuardCellsNum_Doppler - 1), :)], 1);
        elseif DopplerIdx >= rows - GuardCellsNum_Doppler                  % 检测单元Idx下方没有参考单元,取上方对应位置多普勒单元
            Train_Up(DopplerIdx, :) = mean(rd(DopplerIdx - GuardCellsNum_Doppler - TrainCellsNum_Doppler : DopplerIdx - GuardCellsNum_Doppler - 1, :), 1);
            Train_Down(DopplerIdx, :) = mean(rd(GuardCellsNum_Doppler - (rows - DopplerIdx) + 1 : GuardCellsNum_Doppler - (rows - DopplerIdx) + TrainCellsNum_Doppler, :), 1);
        elseif (DopplerIdx >= rows - GuardCellsNum_Doppler - TrainCellsNum_Doppler + 1) && (DopplerIdx < rows - GuardCellsNum_Doppler)  % 检测单元Idx下方有参考单元,但个数<TrainCellsNum_Doppler
            Train_Up(DopplerIdx, :) = mean(rd(DopplerIdx - GuardCellsNum_Doppler - TrainCellsNum_Doppler : DopplerIdx - GuardCellsNum_Doppler - 1, :), 1);
            Train_Down(DopplerIdx, :) = mean([rd(DopplerIdx + GuardCellsNum_Doppler + 1 : rows, :); rd(1 : DopplerIdx + GuardCellsNum_Doppler + TrainCellsNum_Doppler - rows, :)], 1);
        else                                                               % 检测单元Idx上下两侧都有TrainCellsNum_Doppler个参考单元
             Train_Up(DopplerIdx, :) = mean(rd(DopplerIdx - GuardCellsNum_Doppler - TrainCellsNum_Doppler : DopplerIdx - GuardCellsNum_Doppler - 1, :), 1);
             Train_Down(DopplerIdx, :) = mean(rd(DopplerIdx + GuardCellsNum_Doppler + 1 : DopplerIdx + GuardCellsNum_Doppler + TrainCellsNum_Doppler, :), 1);
        end
        [Value,~] = sort([Train_Left(DopplerIdx, RangeIdx), Train_Right(DopplerIdx, RangeIdx), Train_Up(DopplerIdx, RangeIdx), Train_Down(DopplerIdx, RangeIdx)]);
        BackgroundNoise(DopplerIdx, RangeIdx) = Value(3) + Value(4)*0.01;  % 引入一定比例的最大值,考虑降低一些误报.
    end
end

% cfar_thdb=14;
% [Dopplersn,Rangesn] = find(rd > BackgroundNoise*(10.^(cfar_thdb/20)));
[Dopplersn,Rangesn] = find(rd > BackgroundNoise.*SoftCopy_thre);

% 绘制当前CFAR结果 %
figure (97)
plot(Rangesn, Dopplersn, 'r.');
hold on; grid on;
title('十字CFAR结果');
xlim([0 256]); ylim([0 256]);
xlabel('RangeBin,dR');ylabel('DopplerBin,dV');

end

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值