clear all;close all;clc;
%% ----------------参数设置 ----------------%
sampleNum=64; %采样点数
deltaR=0.312;%m
Tx=2; %发射阵元数
Rx=4; %接收阵元数
frameNum=1; %总帧数
pulse=128; %积累脉冲数
virtual=Tx*Rx; %虚拟阵元个数
d_lamda=0.5; %距离和波长的比值
theta=(-60:1:60)*pi/180; %角度扫描范围
jiaodu=(-60:1:60);
Real=0;% 实采样real设为1,复采样complex1x设为0
data=DCA1000_With_1843('adc_data.bin',sampleNum,Rx,Real);
%% 数据重排
Rx1=reshape(data(1,1:sampleNum*Tx*pulse*frameNum),sampleNum,Tx*pulse,frameNum);
Rx11=Rx1(:,1:2:end,:); %Tx1发射Rx1接收
Rx21=Rx1(:,2:2:end,:); %Tx2发射Rx1接收
Rx2=reshape(data(2,1:sampleNum*Tx*pulse*frameNum),sampleNum,Tx*pulse,frameNum);
Rx12=Rx2(:,1:2:end,:); %Tx1发射Rx2接收
Rx22=Rx2(:,2:2:end,:); %Tx2发射Rx2接收
Rx3=reshape(data(3,1:sampleNum*Tx*pulse*frameNum),sampleNum,Tx*pulse,frameNum);
Rx13=Rx3(:,1:2:end,:); %Tx1发射Rx3接收
Rx23=Rx3(:,2:2:end,:); %Tx2发射Rx3接收
Rx4=reshape(data(4,1:sampleNum*Tx*pulse*frameNum),sampleNum,Tx*pulse,frameNum);
Rx14=Rx4(:,1:2:end,:); %Tx1发射Rx1接收
Rx24=Rx4(:,2:2:end,:); %Tx2发射Rx1接收
%% RAWADC数据
showFrame=1; %观察某一帧的处理结果
Rx11_I=real(Rx11(:,1,showFrame)); %I信
Rx11_Q=imag(Rx11(:,1,showFrame)); %Q信号
Rx12_I=real(Rx12(:,1,showFrame)); %I信号
Rx12_Q=imag(Rx12(:,1,showFrame)); %Q信号
Rx13_I=real(Rx13(:,1,showFrame)); %I信号
Rx13_Q=imag(Rx13(:,1,showFrame)); %Q信号
Rx14_I=real(Rx14(:,1,showFrame)); %I信号
Rx14_Q=imag(Rx14(:,1,showFrame)); %Q信号
figure; %I,Q信号
subplot(2,2,1);
set(gcf,'color',[1,1,1])
plot(Rx11_I,'b');hold on;
plot(Rx11_Q,'r');
xlabel('采样点数');ylabel('幅度');title('Rx11接收信号');
ylim([(min([min(Rx11_I) min(Rx11_Q)])-10) (max([max(Rx11_I) max(Rx11_Q)])+10)]);
subplot(2,2,2);
set(gcf,'color',[1,1,1])
plot(Rx12_I,'b');hold on;
plot(Rx12_Q,'r');
xlabel('采样点数');ylabel('幅度');title('Rx12接收信号');
ylim([(min([min(Rx12_I) min(Rx12_Q)])-10) (max([max(Rx12_I) max(Rx12_Q)])+10)]);
subplot(2,2,3);
set(gcf,'color',[1,1,1])
plot(Rx13_I,'b');hold on;
plot(Rx13_Q,'r');
xlabel('采样点数');ylabel('幅度');title('Rx13接收信号');
ylim([(min([min(Rx13_I) min(Rx13_Q)])-10) (max([max(Rx13_I) max(Rx13_Q)])+10)]);
subplot(2,2,4);
set(gcf,'color',[1,1,1])
plot(Rx14_I,'b');hold on;
plot(Rx14_Q,'r');
xlabel('采样点数');ylabel('幅度');title('Rx14接收信号');
ylim([(min([min(Rx14_I) min(Rx14_Q)])-10) (max([max(Rx14_I) max(Rx14_Q)])+10)]);
Rx11_f=fft(Rx11(:,:,showFrame));
Rx12_f=fft(Rx12(:,:,showFrame));
Rx13_f=fft(Rx13(:,:,showFrame));
Rx14_f=fft(Rx14(:,:,showFrame));
Rx21_f=fft(Rx21(:,:,showFrame));
Rx22_f=fft(Rx22(:,:,showFrame));
Rx23_f=fft(Rx23(:,:,showFrame));
Rx24_f=fft(Rx24(:,:,showFrame));
figure; %画第一通道脉压后的图
subplot(2,1,1);
plot(abs(Rx11_f(:,1))); % 画出一维fft后的频谱图
set(gca,'XLim',[1,64]);
xlabel('采样点');ylabel('幅度');title('Rx1 一维FFT后的频谱图');
subplot(2,1,2);
plot((0:(sampleNum-1))*deltaR,(abs(Rx11_f(:,1)))); % 脉压后的距离图
set(gca,'XLim',[0,19.656]);
xlabel('距离/m');ylabel('幅度');title('通道1脉压后距离像');
%% 相干积累+ fftshift
Rx11_ff=fft(Rx11_f,[],2);
Rx11_ff=fftshift(Rx11_ff,2);
Rx12_ff=fft(Rx12_f,[],2);
Rx12_ff=fftshift(Rx12_ff,2);
Rx13_ff=fft(Rx13_f,[],2);
Rx13_ff=fftshift(Rx13_ff,2);
Rx14_ff=fft(Rx14_f,[],2);
Rx14_ff=fftshift(Rx14_ff,2);
Rx21_ff=fft(Rx11_f,[],2);
Rx21_ff=fftshift(Rx21_ff,2);
Rx22_ff=fft(Rx12_f,[],2);
Rx22_ff=fftshift(Rx22_ff,2);
Rx23_ff=fft(Rx13_f,[],2);
Rx23_ff=fftshift(Rx23_ff,2);
Rx24_ff=fft(Rx14_f,[],2);
Rx24_ff=fftshift(Rx24_ff,2);
%% 非相干积累
NoncoRxff=abs(Rx11_ff)+abs(Rx12_ff)+abs(Rx13_ff)+abs(Rx14_ff)+abs(Rx21_ff)+abs(Rx22_ff)+abs(Rx23_ff)+abs(Rx24_ff);
zmin=mean(mean(20*log10(abs(NoncoRxff))))-15;zmax=max(max(20*log10(abs(NoncoRxff))))+5;
NoncoRxff_db=20*log10(NoncoRxff.');NoncoRxff_db=(NoncoRxff_db<zmin).*zmin+(NoncoRxff_db>zmin).*NoncoRxff_db;
%% 数据预处理---把墙体目标去掉
NoncoRxff(11,:)=mean(NoncoRxff,1);
NoncoRxff(10,:)=mean(NoncoRxff,1);
%% 恒虚警处理
DSNR=13;%检测信噪比
refCellNum=20;
proCellNum=2;
%注意:传入CACFAR()的IQ_mtd多普勒维已经过fftshift了
[CFARout,CACFART,cfar_res] = CACFAR_ME(NoncoRxff.',DSNR,refCellNum,proCellNum); %CACFAR(IQ_mtd,DSNR,refCellNum,proCellNum) IQ_mtd参数形式(多普勒维*距离维)
figure;
mesh((0:(sampleNum-1))*deltaR,(-pulse/2:pulse/2-1),20*log10(abs(CFARout+1)));
xlabel('距离/m');ylabel('多普勒通道');zlabel('幅度/dB');grid on;title('恒虚警处理');
point=cfar_res(2:end);
pointcloud=reshape(point,3,cfar_res(1));
figure;
plot(pointcloud(1,:),pointcloud(2,:),'.','MarkerSize',10);
xlabel('距离单元');ylabel('多普勒通道');grid on;title('点云图像');
axis([1 64 1 128]);
%% 质心凝聚
Distance_win=3; %距离窗
Doppler_win=128; %多普勒窗
final_result=target_differ_gai(cfar_res,Distance_win,Doppler_win);
[Rcell,Vcell]=size(Rx11_ff);%距离单元*多普勒单元
final_result_figure=zeros(Vcell,Rcell);
dTarget=final_result(1); %检测目标个数
targetIndex=zeros(dTarget,2); %记录检测目标索引的位置,每一行对应一个目标,第一列对应目标的距离单元,第二列对应目标的多普勒单元
for ii=1:final_result(1)
final_result_figure(final_result(1+3*ii-1),final_result(1+3*ii-2))=final_result(1+3*ii);
targetIndex(ii,1)=final_result(1+3*ii-2);targetIndex(ii,2)=final_result(1+3*ii-1);
end
figure;mesh(20*log10(abs(final_result_figure+1)));
xlabel('距离单元');ylabel('多普勒通道');zlabel('幅度/dB');grid on;title('质心凝聚');
figure;mesh((0:(sampleNum-1))*deltaR,(-pulse/2:pulse/2-1),20*log10(abs(final_result_figure+1))); %
xlabel('距离/m');ylabel('多普勒通道');zlabel('幅度/dB');grid on;title('质心凝聚');
axis tight;
%% 数字波束形成(DBF)
dTarget=1;%根据自己设置的场景中的目标个数选取
rangebin=5;%目标所在距离单元
a=exp(1j*2*pi*(0:virtual-1).'*d_lamda*sin(theta));
dCellData=zeros(dTarget,virtual); %目标检测单元数据
eTheta=zeros(1,dTarget); %目标检测角度
eRange=(rangebin-1)*deltaR; %目标检测距离
pattern=zeros(dTarget,length(theta),length(Rx11_f(:,1))); %波束图
for rangebinloop=1:64
for i=1:dTarget
dCellData(1,1)=Rx11_ff(rangebinloop,65);
dCellData(1,2)=Rx12_ff(rangebinloop,65);
dCellData(1,3)=Rx13_ff(rangebinloop,65);
dCellData(1,4)=Rx14_ff(rangebinloop,65);
dCellData(1,5)=Rx21_ff(rangebinloop,65);
dCellData(1,6)=Rx22_ff(rangebinloop,65);
dCellData(1,7)=Rx23_ff(rangebinloop,65);
dCellData(1,8)=Rx24_ff(rangebinloop,65);
pattern(i,:,rangebinloop)=dCellData(i,:)*conj(a);
end
end
figure;
plot(theta*180/pi,(20*log10(abs(pattern(1,:,rangebin)))),'LineWidth',2);
xlabel('方位角/^o');ylabel('幅度/dB');title('DBF处理');grid on;legend('MIMO');
%% 热图描画 %%
Pattern1=reshape(pattern(1,:,:),length(theta),length(Rx11_f(:,1)));
PatterndB=abs((Pattern1.').*(Pattern1.')) ;%行为距离单元,列为扫描角度
lim=1:10;%显示范围
figure;
heatmapMax = max(max(PatterndB(lim,:)));
if (heatmapMax < 1000)
cLim = [0, 1000];
else
cLim = [0, heatmapMax];
end
% imagesc(jiaodu,((lim-1).*deltaR), PatterndB(lim,:), cLim);
% set(gca,'YDir','normal');%就是让 y 轴的刻度顺序设置为 "正常",也就是刻度从下往上是依次增大的.如果你希望反过来,就是 >> set(gca,'YDir','reverse')
% xlabel('角度');
% ylabel('距离');grid on;
displayPolarHeatmap( PatterndB(lim,:), jiaodu*pi/180,((lim-1).*deltaR));
function displayPolarHeatmap(rangeAzimuth_2plot, theta, range)
global rollingMax
global rollingAvg
global rollingIdx
%figure;
heatmapMax = max(rangeAzimuth_2plot(:));
imagesc_polar2(theta, range, rangeAzimuth_2plot);
xlabel('水平距离[m]');
ylabel('垂直距离[m]');
yLim = [0, range(end)];
xLim = yLim(2)*sin(max(abs(theta))) * [-1,1];
ylim(yLim);
xlim(xLim);
delta = 0.5;
set(gca, 'Xtick', [-50:delta:50]);
set(gca, 'Ytick', [0:delta:100]);
set(gca,'Color', [0.5 0.5 0.5])
grid on;
return
end
function imagesc_polar2(theta, rr, im) %==>>
% Plot imagesc-like plot in polar coordinates using pcolor()
% transform data in polar coordinates to Cartesian coordinates.
YY = rr'*cos(theta);
XX = rr'*sin(theta);
% plot data on top of grid
h = pcolor(XX, YY, im);
shading flat
grid on;
axis equal;
return
end