clear;close all;clc;tic;dirOutput = dir('*.dat'); % 罗列所有后缀-1.dat的文件列表,罗列BDDATA的数据
filenames = string({dirOutput.name}'); % 提取文件名%% 丢包统计
FILENAMES = [""];
LOSS_YTJ = [ ];
LOSS_RAD = [ ];
LOSS_ETH = [ ];
LOSS_YK = [ ];
j=1;%% 批处理
for i = 1:length(filenames)%% 文件名filename = char(filenames(i)); filename = string(filename([1:end-16])); % 例如:20090111-190130-2%% 加载数据文件TELEMETRY_fileID = fopen(filename+'TELEMETRY-v1.dat'); % 获取 TELEMETRY 文件ID DATA_TELEMETRY = fread(TELEMETRY_fileID); % 读取 TELEMETRY 文件数据fclose(TELEMETRY_fileID); % 关闭文件%% 解析数据文件TELEMETRY_RAW = reshape(DATA_TELEMETRY,[ 239 length(DATA_TELEMETRY)/239])'; % 帧格式转换cnt_yaoce_link = TELEMETRY_RAW(:,17); % 遥测链路cnt (239字节的第17字节)time_yitiji = (TELEMETRY_RAW(:,234)*2^8 + TELEMETRY_RAW(:,233)) ; % 一体机时间 (239字节的第234、233字节)cnt_gnd_eth = TELEMETRY_RAW(:,13); % 地面接口网口cnt (239字节的第13字节)ip_config = TELEMETRY_RAW(:,30); % 电台反馈IP (239字节的第30字节)cfk_ml = TELEMETRY_RAW(:,31); % 最近测发控指令 (239字节的第31字节)signal_power = TELEMETRY_RAW(:,32); % 遥控信号能量值单字节 (239字节的第32字节)zijian = TELEMETRY_RAW(:,33); % 自检完成 (239字节的第33字节)state_yaokong = TELEMETRY_RAW(:,32); % 遥控链路通断状态 (239字节的第32字节)control_yaokong = TELEMETRY_RAW(:,36)*2^8+TELEMETRY_RAW(:,35); % 地面遥控指令是否连续 (239字节的第36、35字节)angle_cabrage = (TELEMETRY_RAW(:,50)*2^8 + TELEMETRY_RAW(:,49)) * 0.01; % 飞行姿态 俯仰 (239字节第50、49)angle_roll = (TELEMETRY_RAW(:,52)*2^8 + TELEMETRY_RAW(:,51)) * 0.01; % 飞行姿态 滚动 (239字节第52、51)angle_Heading = (TELEMETRY_RAW(:,54)*2^8 + TELEMETRY_RAW(:,53)) * 0.01; % 飞行姿态 航向 (239字节第54、53)speed_bd = TELEMETRY_RAW(:,149)*0.005; % 靶弹飞行速度 (239字节第149字节)high_bd = (TELEMETRY_RAW(:,88)*2^8+TELEMETRY_RAW(:,87))*0.2-500; % 靶弹飞行高度 (239字节第88、87字节)len_tele = length(cnt_yaoce_link); % TELEMETRY 数据长度%% 数据处理% 遥测链路是否丢包,前后相减是否为1diubao_yaoce_link = diff(cnt_yaoce_link);diubao_yaoce_link(diubao_yaoce_link <= 0) = diubao_yaoce_link(diubao_yaoce_link <= 0) + 256; % 处理负数flag_diubao_yaoce_link = diubao_yaoce_link ~= 1; % 遥测链路丢包时刻count_diubao_yaoce_link = sum(diubao_yaoce_link-1); % 遥测链路丢包数% 遥测是否丢包,基于一体机,前后相减是否为1 diubao_yaoce_yitiji = diff(time_yitiji);
% diubao_yaoce_yitiji(diubao_yaoce_yitiji == -65535) = 1; % 处理负数diubao_yaoce_yitiji(diubao_yaoce_yitiji < 0) = diubao_yaoce_yitiji(diubao_yaoce_yitiji < 0) + 65536; % 处理负数flag_diubao_yaoce_yitiji = diubao_yaoce_yitiji ~= 1; % 遥测丢包时刻count_diubao_yaoce_yitiji = sum(diubao_yaoce_yitiji-1); % 遥测总丢包数% 地面网口接口是否丢包,前后相减是否为1diubao_gnd_eth = diff(cnt_gnd_eth);diubao_gnd_eth(diubao_gnd_eth <= 0) = diubao_gnd_eth(diubao_gnd_eth <= 0) + 256; % 处理负数flag_diubao_gnd_eth = diubao_gnd_eth ~= 1; % 地面网口丢包时刻count_diubao_gnd_eth = sum(diubao_gnd_eth-1); % 地面网口丢包数% 链路能量情况,整个字节显示% 自检完成,加载成功,判断是否等于FFstate_zijian = zijian == 0xff;% 遥控链路通断状态(大于0即可)state_yk_link = state_yaokong > 0;% 地面遥控指令是否连续(是否存在00)state_yk_zl = control_yaokong == 0;k=1;while state_yk_zl(k) == 1 && k < 500 % 清除错误的数值,容错前50个。state_yk_zl(k) = 0;k = k+1; endcount_state_yk_zl = sum(state_yk_zl); % 遥控总丢包数flag_state_yk_zl = state_yk_zl ~= 0;% 遥控指令切换状态,切换计数器% 角度负数处理angle_cabrage(angle_cabrage>327.67) = angle_cabrage(angle_cabrage>327.67) - 655.36; angle_roll(angle_roll>327.67) = angle_roll(angle_roll>327.67) - 655.36; angle_Heading(angle_Heading>327.67) = angle_Heading(angle_Heading>327.67) - 655.36; % 统计丢包数(网络、链路、遥测、遥控)FILENAMES(j) = filename; % 文件名称
% LOSS_YTJ(j) = count_diubao_yaoce_yitiji - count_diubao_yaoce_link; % 一体机丢包
% LOSS_RAD(j) = count_diubao_yaoce_link - count_diubao_gnd_eth; % 遥测链路丢包LOSS_YTJ(j) = count_diubao_yaoce_yitiji ; % 一体机丢包LOSS_RAD(j) = count_diubao_yaoce_link ; % 遥测链路丢包LOSS_ETH(j) = count_diubao_gnd_eth; % 以太网丢包LOSS_YK(j) = count_state_yk_zl; % 遥控丢包disp('如上图所示,网络丢'+string(LOSS_ETH(j))+'包,遥测链路丢'+string(LOSS_RAD(j))+'包,一体机丢'+string(LOSS_YTJ(j))+'包。'); % 快速报告j=j+1;%% 创建对应文件名的文件夹mkdir(filename);%% 绘制第一类图 : 丢包 帧计数(网络、链路、遥测、指令) ( BD 指令和指令切换时刻)img = gcf;clf(img);hold on;plot(flag_diubao_gnd_eth*150,'--');plot(flag_diubao_yaoce_link*140,'.');plot(flag_diubao_yaoce_yitiji*130,'s');plot(cfk_ml,'r');plot([0,len_tele],[97,97],'linestyle','--');plot([0,len_tele],[113,113],'linestyle','--');legend('网络丢包','链路丢包','一体机丢包','指令','0x61大小功率','0x71数据装订','Location','NorthEastOutside');title('丢包与帧计数(网络、链路、遥测、指令)');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/1_1丢包帧计数与指令.png');savefig(img,filename+'/1_1丢包帧计数与指令.fig');% clf(img);
% hold on;
% plot(state_yk_qie(:,2),'r');
% plot(yk_zl_qiehuan*150,'g--');
% plot([0,len_bd],[97,97],'linestyle','--');
% plot([0,len_bd],[113,113],'linestyle','--');
% legend('指令','指令切换时刻','0x61大小功率','0x71数据装订','Location','NorthEastOutside');
% ylim([-0.3 155]);
% hold off;
% print(img,'-dpng','-r800',filename+'/1_2靶弹指令和指令切换时刻.png');
% savefig(img,filename+'/1_2靶弹指令和指令切换时刻.fig');%% 绘制第二类图 遥控信号能量 & 遥控丢包 & 自检完成clf(img);hold on;plot(signal_power,'r');% 通断、其余未断链plot([0,len_tele],[0,0],'linestyle','--'); % 大信号plot([0,len_tele],[48,48],'linestyle','--');plot([0,len_tele],[95,95],'linestyle','--');% 中信号plot([0,len_tele],[96,96],'linestyle','--');plot([0,len_tele],[143,143],'linestyle','--');% 小信号plot([0,len_tele],[144,144],'linestyle','--');plot([0,len_tele],[191,191],'linestyle','--');% 遥控丢包plot(flag_state_yk_zl*150,'g');% 自检plot(state_zijian * 10); % 自检title('遥控信号能量 & 遥控丢包 & 自检完成');legend('遥控信号能量','通断','大信号上限','大信号下限', ...'中信号下限','中信号上限','小信号下限','小信号上限',...'遥控丢包','自检完成','Location','NorthEastOutside');hold off;print(img,'-dpng','-r800',filename+'/2_遥控丢包_遥控能量.png');savefig(img,filename+'/2_遥控丢包_遥控能量.fig');%% 绘制第三类图 飞行 (俯仰、滚动、航向)
% clf(img);
% hold on;
% plot(angle_cabrage);
% plot(angle_roll);
% plot(angle_Heading);
% title('俯仰、滚动、航向');
% ylim([-180 180]);
% hold off;
% print(img,'-dpng','-r800',filename+'/3_飞行角度.png');
% savefig(img,filename+'/3_飞行角度.fig'); %% 绘制第四类图 IP分析图
% clf(img);
% plot(ip_config);
% title('IP反馈图');
% print(img,'-dpng','-r800',filename+'/4_IP反馈图.png');
% savefig(img,filename+'/4_IP反馈图.fig'); %% 纯链路丢包clf(img);hold on;plot((flag_diubao_yaoce_link-flag_diubao_gnd_eth)*150,'--');plot(cfk_ml,'r');plot([0,len_tele],[97,97],'linestyle','--');plot([0,len_tele],[113,113],'linestyle','--');legend('链路丢包','指令','0x61大小功率','0x71数据装订','Location','NorthEastOutside');title('链路丢包与帧计数(链路、指令)');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/5丢包帧计数与指令.png');savefig(img,filename+'/5纯链路丢包帧计数与指令.fig');%% 纯一体机丢包clf(img);hold on;plot((flag_diubao_yaoce_yitiji-flag_diubao_yaoce_link)*150,'--');plot(cfk_ml,'r');plot([0,len_tele],[97,97],'linestyle','--');plot([0,len_tele],[113,113],'linestyle','--');legend('一体机丢包','指令','0x61大小功率','0x71数据装订','Location','NorthEastOutside');title('一体机丢包与帧计数(链路、指令)');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/6丢包帧计数与指令.png');savefig(img,filename+'/6纯一体丢包帧计数与指令.fig');%% 纯网络丢包clf(img);hold on;plot(flag_diubao_gnd_eth*150,'--');plot(cfk_ml,'r');plot([0,len_tele],[97,97],'linestyle','--');plot([0,len_tele],[113,113],'linestyle','--');legend('网络链路丢包','指令','0x61大小功率','0x71数据装订','Location','NorthEastOutside');title('网络丢包与帧计数(链路、指令)');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/7丢包帧计数与指令.png');savefig(img,filename+'/7纯网络丢包帧计数与指令.fig');save(filename+'/8_data.mat', ...'cnt_yaoce_link','diubao_yaoce_link','flag_diubao_yaoce_link', ...'time_yitiji','diubao_yaoce_yitiji','flag_diubao_yaoce_yitiji', ...'cnt_gnd_eth','diubao_gnd_eth','flag_diubao_gnd_eth');
end%% 数据统计与导出
FILENAMES=FILENAMES';
LOSS_YTJ = LOSS_YTJ';
LOSS_RAD=LOSS_RAD';
LOSS_ETH=LOSS_ETH';
LOSS_YK=LOSS_YK';writetable(table(FILENAMES,LOSS_YTJ,LOSS_RAD,LOSS_ETH,LOSS_YK,'VariableNames',["FILENAMES","LOSS_YTJ","LOSS_RAD","LOSS_ETH","LOSS_YK"]),'丢包数据统计(一体机丢包-遥测链路丢包-地面网口丢包-遥控丢包).csv');toc;
%% 清空
clear all;close all;clc;
tic; % 计时dirOutput = dir('*-1.dat'); % 罗列所有后缀-1.dat的文件列表,罗列BDDATA的数据
filenames = string({dirOutput.name}'); % 提取文件名%% 丢包统计
FILENAMES = [""];
LOSS_YTJ = [ ];
LOSS_RAD = [ ];
LOSS_ETH = [ ];
LOSS_YK = [ ];
j=1;%% 批处理
for i = 1:length(filenames)%% 文件名filename = char(filenames(i)); filename = string(filename([1:end-16])); % 例如:20090111-190130-2%% 加载数据文件BDDATA_fileID = fopen(filename+'-A2-BDDATA-1.dat'); % 获取 BDDATA 文件ID TELEMETRY_fileID = fopen(filename+'-C2-TELEMETRY-v1.dat'); % 获取 TELEMETRY 文件ID DATA_BDDATA = fread(BDDATA_fileID); % 读取 BDDATA 文件数据DATA_TELEMETRY = fread(TELEMETRY_fileID); % 读取 TELEMETRY 文件数据fclose(BDDATA_fileID); fclose(TELEMETRY_fileID); % 关闭文件%% 解析数据文件TELEMETRY_RAW = reshape(DATA_TELEMETRY,[ 239 length(DATA_TELEMETRY)/239])'; % 帧格式转换BDDATA_RAW = reshape(DATA_BDDATA ,[ 178 length(DATA_BDDATA )/178])'; % 帧格式转换cnt_yaoce_link = TELEMETRY_RAW(:,17); % 遥测链路cnt (239字节的第17字节)time_yitiji = (TELEMETRY_RAW(:,234)*2^8 + TELEMETRY_RAW(:,233)) ; % 一体机时间 (239字节的第234、233字节)cnt_gnd_eth = TELEMETRY_RAW(:,13); % 地面接口网口cnt (239字节的第13字节)ip_config = TELEMETRY_RAW(:,30); % 电台反馈IP (239字节的第30字节)cfk_ml = TELEMETRY_RAW(:,31); % 最近测发控指令 (239字节的第31字节)signal_power = TELEMETRY_RAW(:,32); % 遥控信号能量值单字节 (239字节的第32字节)zijian = TELEMETRY_RAW(:,33); % 自检完成 (239字节的第33字节)state_yaokong = TELEMETRY_RAW(:,32); % 遥控链路通断状态 (239字节的第32字节)control_yaokong = TELEMETRY_RAW(:,36)*2^8+TELEMETRY_RAW(:,35); % 地面遥控指令是否连续 (239字节的第36、35字节)angle_cabrage = (TELEMETRY_RAW(:,50)*2^8 + TELEMETRY_RAW(:,49)) * 0.01; % 飞行姿态 俯仰 (239字节第50、49)angle_roll = (TELEMETRY_RAW(:,52)*2^8 + TELEMETRY_RAW(:,51)) * 0.01; % 飞行姿态 滚动 (239字节第52、51)angle_Heading = (TELEMETRY_RAW(:,54)*2^8 + TELEMETRY_RAW(:,53)) * 0.01; % 飞行姿态 航向 (239字节第54、53)speed_bd = TELEMETRY_RAW(:,149)*0.005; % 靶弹飞行速度 (239字节第149字节)high_bd = (TELEMETRY_RAW(:,88)*2^8+TELEMETRY_RAW(:,87))*0.2-500; % 靶弹飞行高度 (239字节第88、87字节)state_yk_qie = BDDATA_RAW(:,[11 10]); % 遥控指令切换状态(阶梯状),BD_DATA里面第11(计数)、10(指令)字节。time_bd_yitiji = (BDDATA_RAW(:,24)*2^24+BDDATA_RAW(:,23)*2^16+BDDATA_RAW(:,22)*2^8+BDDATA_RAW(:,21))*0.00001;len_tele = length(cnt_yaoce_link); % TELEMETRY 数据长度len_bd = length(state_yk_qie); % BDDATA 数据长度%% 数据处理% 遥测链路是否丢包,前后相减是否为1diubao_yaoce_link = diff(cnt_yaoce_link);diubao_yaoce_link(diubao_yaoce_link <= 0) = diubao_yaoce_link(diubao_yaoce_link <= 0) + 256; % 处理负数flag_diubao_yaoce_link = diubao_yaoce_link ~= 1; % 遥测链路丢包时刻count_diubao_yaoce_link = sum(diubao_yaoce_link-1); % 遥测链路丢包数% 遥测是否丢包,基于一体机,前后相减是否为1 diubao_yaoce_yitiji = diff(time_yitiji);diubao_yaoce_yitiji(diubao_yaoce_yitiji < 0) = diubao_yaoce_yitiji(diubao_yaoce_yitiji < 0) + 65536; % 处理负数flag_diubao_yaoce_yitiji = diubao_yaoce_yitiji ~= 1; % 遥测丢包时刻count_diubao_yaoce_yitiji = sum(diubao_yaoce_yitiji-1); % 遥测总丢包数% 地面网口接口是否丢包,前后相减是否为1diubao_gnd_eth = diff(cnt_gnd_eth);diubao_gnd_eth(diubao_gnd_eth <= 0) = diubao_gnd_eth(diubao_gnd_eth <= 0) + 256; % 处理负数flag_diubao_gnd_eth = diubao_gnd_eth ~= 1; % 地面网口丢包时刻count_diubao_gnd_eth = sum(diubao_gnd_eth-1); % 地面网口丢包数% 链路能量情况,整个字节显示% 自检完成,加载成功,判断是否等于FFstate_zijian = zijian == 0xff;% 遥控链路通断状态(大于0即可)state_yk_link = state_yaokong > 0;% 地面遥控指令是否连续(是否存在00)state_yk_zl = control_yaokong == 0;k=1;while state_yk_zl(k) == 1 && k < 500 % 清除错误的数值,容错前50个。state_yk_zl(k) = 0;k = k+1; endcount_state_yk_zl = sum(state_yk_zl); % 遥控总丢包数flag_state_yk_zl = state_yk_zl ~= 0;% 遥控指令切换状态,切换计数器yk_zl_qiehuan = diff(state_yk_qie(:,1));% 角度负数处理angle_cabrage(angle_cabrage>327.67) = angle_cabrage(angle_cabrage>327.67) - 655.36; angle_roll(angle_roll>327.67) = angle_roll(angle_roll>327.67) - 655.36; angle_Heading(angle_Heading>327.67) = angle_Heading(angle_Heading>327.67) - 655.36; % 统计丢包数(网络、链路、遥测、遥控)FILENAMES(j) = filename; % 文件名称
% LOSS_YTJ(j) = count_diubao_yaoce_yitiji - count_diubao_yaoce_link; % 一体机丢包
% LOSS_RAD(j) = count_diubao_yaoce_link - count_diubao_gnd_eth; % 遥测链路丢包LOSS_YTJ(j) = count_diubao_yaoce_yitiji ; % 一体机丢包LOSS_RAD(j) = count_diubao_yaoce_link ; % 遥测链路丢包LOSS_ETH(j) = count_diubao_gnd_eth; % 以太网丢包LOSS_YK(j) = count_state_yk_zl; % 遥控丢包disp('如上图所示,网络丢'+string(LOSS_ETH(j))+'包,遥测链路丢'+string(LOSS_RAD(j))+'包,一体机丢'+string(LOSS_YTJ(j))+'包。'); % 快速报告j=j+1;%% 创建对应文件名的文件夹mkdir(filename);%% 绘制第一类图 : 丢包 帧计数(网络、链路、遥测、指令) ( BD 指令和指令切换时刻)img = gcf;clf(img);hold on;plot(flag_diubao_gnd_eth*150,'--');plot(flag_diubao_yaoce_link*140,'.');plot(flag_diubao_yaoce_yitiji*130,'s');plot(cfk_ml,'r');plot([0,len_tele],[97,97],'linestyle','--');plot([0,len_tele],[113,113],'linestyle','--');legend('网络丢包','链路丢包','一体机丢包','指令','0x61大小功率','0x71数据装订','Location','NorthEastOutside');title('丢包与帧计数(网络、链路、遥测、指令)');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/1_1丢包帧计数与指令.png');savefig(img,filename+'/1_1丢包帧计数与指令.fig');clf(img);hold on;plot(state_yk_qie(:,2),'r');plot(yk_zl_qiehuan*150,'g--');plot([0,len_bd],[97,97],'linestyle','--');plot([0,len_bd],[113,113],'linestyle','--');legend('指令','指令切换时刻','0x61大小功率','0x71数据装订','Location','NorthEastOutside');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/1_2靶弹指令和指令切换时刻.png');savefig(img,filename+'/1_2靶弹指令和指令切换时刻.fig');%% 绘制第二类图 遥控信号能量 & 遥控丢包 & 自检完成clf(img);hold on;plot(signal_power,'r');% 通断、其余未断链plot([0,len_tele],[0,0],'linestyle','--'); % 大信号plot([0,len_tele],[48,48],'linestyle','--');plot([0,len_tele],[95,95],'linestyle','--');% 中信号plot([0,len_tele],[96,96],'linestyle','--');plot([0,len_tele],[143,143],'linestyle','--');% 小信号plot([0,len_tele],[144,144],'linestyle','--');plot([0,len_tele],[191,191],'linestyle','--');% 遥控丢包plot(flag_state_yk_zl*150,'g');% 自检plot(state_zijian * 10); % 自检title('遥控信号能量 & 遥控丢包 & 自检完成');legend('遥控信号能量','通断','大信号上限','大信号下限', ...'中信号下限','中信号上限','小信号下限','小信号上限',...'遥控丢包','自检完成','Location','NorthEastOutside');hold off;print(img,'-dpng','-r800',filename+'/2_遥控丢包_遥控能量.png');savefig(img,filename+'/2_遥控丢包_遥控能量.fig');%% 绘制第三类图 飞行 (俯仰、滚动、航向)
% clf(img);
% hold on;
% plot(angle_cabrage);
% plot(angle_roll);
% plot(angle_Heading);
% title('俯仰、滚动、航向');
% ylim([-180 180]);
% hold off;
% print(img,'-dpng','-r800',filename+'/3_飞行角度.png');
% savefig(img,filename+'/3_飞行角度.fig'); %% 绘制第四类图 IP分析图clf(img);plot(ip_config);title('IP反馈图');print(img,'-dpng','-r800',filename+'/4_IP反馈图.png');savefig(img,filename+'/4_IP反馈图.fig'); %% 纯链路丢包clf(img);hold on;plot((flag_diubao_yaoce_link-flag_diubao_gnd_eth)*150,'--');plot(cfk_ml,'r');plot([0,len_tele],[97,97],'linestyle','--');plot([0,len_tele],[113,113],'linestyle','--');legend('链路丢包','指令','0x61大小功率','0x71数据装订','Location','NorthEastOutside');title('链路丢包与帧计数(链路、指令)');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/5丢包帧计数与指令.png');savefig(img,filename+'/5纯链路丢包帧计数与指令.fig');%% 纯一体机丢包clf(img);hold on;plot((flag_diubao_yaoce_yitiji-flag_diubao_yaoce_link)*150,'--');plot(cfk_ml,'r');plot([0,len_tele],[97,97],'linestyle','--');plot([0,len_tele],[113,113],'linestyle','--');legend('一体机丢包','指令','0x61大小功率','0x71数据装订','Location','NorthEastOutside');title('一体机丢包与帧计数(链路、指令)');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/6丢包帧计数与指令.png');savefig(img,filename+'/6纯一体丢包帧计数与指令.fig');%% 纯网络丢包clf(img);hold on;plot(flag_diubao_gnd_eth*150,'--');plot(cfk_ml,'r');plot([0,len_tele],[97,97],'linestyle','--');plot([0,len_tele],[113,113],'linestyle','--');legend('网络链路丢包','指令','0x61大小功率','0x71数据装订','Location','NorthEastOutside');title('网络丢包与帧计数(链路、指令)');ylim([-0.3 155]);hold off;print(img,'-dpng','-r800',filename+'/7丢包帧计数与指令.png');savefig(img,filename+'/7纯网络丢包帧计数与指令.fig');save(filename+'/8_data.mat', ...'cnt_yaoce_link','diubao_yaoce_link','flag_diubao_yaoce_link', ...'time_yitiji','diubao_yaoce_yitiji','flag_diubao_yaoce_yitiji', ...'cnt_gnd_eth','diubao_gnd_eth','flag_diubao_gnd_eth');
end%% 数据统计与导出
FILENAMES=FILENAMES';
LOSS_YTJ = LOSS_YTJ';
LOSS_RAD=LOSS_RAD';
LOSS_ETH=LOSS_ETH';
LOSS_YK=LOSS_YK';writetable(table(FILENAMES,LOSS_YTJ,LOSS_RAD,LOSS_ETH,LOSS_YK,'VariableNames',["FILENAMES","LOSS_YTJ","LOSS_RAD","LOSS_ETH","LOSS_YK"]),'丢包数据统计(一体机丢包-遥测链路丢包-地面网口丢包-遥控丢包).csv');toc;
ALL
% 计时
tic; %% 丢包统计
FILENAMES = [""];
LOSS_YTJ = [ ];
LOSS_RAD = [ ];
LOSS_ETH = [ ];
LOSS_YK = [ ];%% 加载数据文件
BD_fileID = fopen('bd.dat'); % 获取 靶弹 文件ID
ZHU_fileID = fopen('zhu.dat'); % 获取 主站 文件ID
FU_fileID = fopen('fu.dat'); % 获取 副站 文件ID DATA_BD = fread(BD_fileID); % 读取 靶弹 文件数据
DATA_ZHU = fread(ZHU_fileID); % 读取 主站 文件数据
DATA_FU = fread(FU_fileID); % 读取 副站 文件数据fclose(BD_fileID); fclose(ZHU_fileID); fclose(FU_fileID); % 关闭文件%% 解析数据文件
ZHU_RAW = reshape(DATA_ZHU,[239 length(DATA_ZHU)/239])'; % 主站帧格式转换
FU_RAW = reshape(DATA_FU,[ 239 length(DATA_FU )/239])'; % 副站帧格式转换
BDDATA_RAW = reshape(DATA_BD,[ 178 length(DATA_BD )/178])'; % 靶弹帧格式转换%% 靶弹数据解析
state_yk_qie = BDDATA_RAW(:,[11 10]); % 遥控指令切换状态(阶梯状),BD_DATA里面第11(计数)、10(指令)字节。
time_bd_yitiji = (BDDATA_RAW(:,24)*2^24 + BDDATA_RAW(:,23)*2^16 + ...BDDATA_RAW(:,22)*2^8 + BDDATA_RAW(:,21))*0.00001;
BD_UTC_raw = BDDATA_RAW(:,28)*2^24 + BDDATA_RAW(:,27)*2^16 + ...BDDATA_RAW(:,26)*2^8 + BDDATA_RAW(:,25); % UTC 时间原码 (BD_DATA里面第25、26、27、28字节)
BD_UTC = ConvertNum2UTC(BD_UTC_raw); % BD 的 UTC 时间
len_bd = length(state_yk_qie); % BDDATA 数据长度%% 主站数据解析
zhu_cnt_yaoce_link = ZHU_RAW(:,17); % 遥测链路cnt (239字节的第17字节)
zhu_time_yitiji = (ZHU_RAW(:,234)*2^8 + ZHU_RAW(:,233)) ; % 一体机时间 (239字节的第234、233字节)
zhu_sky_control_time= (ZHU_RAW(:,110)*2^24 + ZHU_RAW(:,109)*2^16 + ...ZHU_RAW(:,108)*2^8 + ZHU_RAW(:,107)); % 飞控时间 (239字节第110、109、108、107)
zhu_cnt_gnd_eth = ZHU_RAW(:,13); % 地面接口网口cnt (239字节的第13字节)
zhu_ip_config = ZHU_RAW(:,30); % 电台反馈IP (239字节的第30字节)
zhu_cfk_ml = ZHU_RAW(:,31); % 最近测发控指令 (239字节的第31字节)
zhu_signal_power = ZHU_RAW(:,32); % 遥控信号能量值单字节 (239字节的第32字节)
zhu_zijian = ZHU_RAW(:,33); % 自检完成 (239字节的第33字节)
zhu_state_yaokong = ZHU_RAW(:,32); % 遥控链路通断状态 (239字节的第32字节)
zhu_control_yaokong = ZHU_RAW(:,36)*2^8 + ZHU_RAW(:,35); % 地面遥控指令是否连续 (239字节的第36、35字节)
zhu_angle_cabrage = (ZHU_RAW(:,50)*2^8 + ZHU_RAW(:,49)) * 0.01; % 飞行姿态 俯仰 (239字节第50、49)
zhu_angle_roll = (ZHU_RAW(:,52)*2^8 + ZHU_RAW(:,51)) * 0.01; % 飞行姿态 滚动 (239字节第52、51)
zhu_angle_Heading = (ZHU_RAW(:,54)*2^8 + ZHU_RAW(:,53)) * 0.01; % 飞行姿态 航向 (239字节第54、53)
zhu_longitude = (ZHU_RAW(:,83)*2^16 + ZHU_RAW(:,82)*2^8 + ...ZHU_RAW(:,81)); % 经度 (239字节第83、82、81)原始数据
zhu_latitude = (ZHU_RAW(:,86)*2^16 + ZHU_RAW(:,85)*2^8 + ...ZHU_RAW(:,84)); % 纬度 (239字节第86、85、84)原始数据
zhu_positiong_high = (ZHU_RAW(:,88)*2^8 + ZHU_RAW(:,87)) * 0.2 - 500; % 高度 (239字节的第88、87字节)
zhu_speed_bd = ZHU_RAW(:,149)*0.005; % 靶弹飞行速度 (239字节第149字节)
zhu_high_bd = (ZHU_RAW(:,88)*2^8 + ZHU_RAW(:,87))*0.2 - 500; % 靶弹飞行高度 (239字节第88、87字节)
zhu_UTC_raw =(ZHU_RAW(:,104)*2^24 + ZHU_RAW(:,103)*2^16 + ...ZHU_RAW(:,102)*2^8 + ZHU_RAW(:,101)); % UTC 时间原码 (239字节第104、103、102、101)
zhu_UTC = ConvertNum2UTC(zhu_UTC_raw); % UTC 时间zhu_len_tele = length(zhu_cnt_yaoce_link); % 主站数据包长度
%% 副站数据解析
fu_cnt_yaoce_link = FU_RAW(:,17); % 遥测链路cnt (239字节的第17字节)
fu_time_yitiji = (FU_RAW(:,234)*2^8 + FU_RAW(:,233)) ; % 一体机时间 (239字节的第234、233字节)
fu_sky_control_time= (FU_RAW(:,110)*2^24 + FU_RAW(:,109)*2^16 + ...FU_RAW(:,108)*2^8 + FU_RAW(:,107)); % 飞控时间 (239字节第110、109、108、107)
fu_cnt_gnd_eth = FU_RAW(:,13); % 地面接口网口cnt (239字节的第13字节)
fu_ip_config = FU_RAW(:,30); % 电台反馈IP (239字节的第30字节)
fu_cfk_ml = FU_RAW(:,31); % 最近测发控指令 (239字节的第31字节)
fu_signal_power = FU_RAW(:,32); % 遥控信号能量值单字节 (239字节的第32字节)
fu_zijian = FU_RAW(:,33); % 自检完成 (239字节的第33字节)
fu_state_yaokong = FU_RAW(:,32); % 遥控链路通断状态 (239字节的第32字节)
fu_control_yaokong = FU_RAW(:,36)*2^8 + FU_RAW(:,35); % 地面遥控指令是否连续 (239字节的第36、35字节)
fu_angle_cabrage = (FU_RAW(:,50)*2^8 + FU_RAW(:,49)) * 0.01; % 飞行姿态 俯仰 (239字节第50、49)
fu_angle_roll = (FU_RAW(:,52)*2^8 + FU_RAW(:,51)) * 0.01; % 飞行姿态 滚动 (239字节第52、51)
fu_angle_Heading = (FU_RAW(:,54)*2^8 + FU_RAW(:,53)) * 0.01; % 飞行姿态 航向 (239字节第54、53)
fu_longitude = (FU_RAW(:,83)*2^16 + FU_RAW(:,82)*2^8 + ...FU_RAW(:,81)); % 经度 (239字节第83、82、81)原始数据
fu_latitude = (FU_RAW(:,86)*2^16 + FU_RAW(:,85)*2^8 + ...FU_RAW(:,84)); % 纬度 (239字节第86、85、84)原始数据
fu_positiong_high = (FU_RAW(:,88)*2^8 + FU_RAW(:,87)) * 0.2 - 500; % 高度 (239字节的第88、87字节)
fu_speed_bd = FU_RAW(:,149)*0.005; % 靶弹飞行速度 (239字节第149字节)
fu_high_bd = (FU_RAW(:,88)*2^8 + FU_RAW(:,87))*0.2-500; % 靶弹飞行高度 (239字节第88、87字节)
fu_UTC_raw =(FU_RAW(:,104)*2^24 + FU_RAW(:,103)*2^16 + ...FU_RAW(:,102)*2^8 + FU_RAW(:,101)); % UTC 时间原码 (239字节第104、103、102、101)
fu_UTC = ConvertNum2UTC(fu_UTC_raw); % UTC 时间
fu_len_tele = length(fu_cnt_yaoce_link); % 副站数据包长度
%% 主站数据处理% 遥测链路是否丢包,前后相减是否为1zhu_diubao_yaoce_link = diff(zhu_cnt_yaoce_link);zhu_diubao_yaoce_link(zhu_diubao_yaoce_link <= 0) = zhu_diubao_yaoce_link(zhu_diubao_yaoce_link <= 0) + 256; % 处理负数zhu_flag_diubao_yaoce_link = zhu_diubao_yaoce_link ~= 1; % 遥测链路丢包时刻zhu_count_diubao_yaoce_link = sum(zhu_diubao_yaoce_link-1); % 遥测链路丢包数% 遥测是否丢包,基于一体机,前后相减是否为1 zhu_diubao_yaoce_yitiji = diff(zhu_time_yitiji);zhu_diubao_yaoce_yitiji(zhu_diubao_yaoce_yitiji < 0) = zhu_diubao_yaoce_yitiji(zhu_diubao_yaoce_yitiji < 0) + 65536; % 处理负数zhu_flag_diubao_yaoce_yitiji = zhu_diubao_yaoce_yitiji ~= 1; % 遥测丢包时刻zhu_count_diubao_yaoce_yitiji = sum(zhu_diubao_yaoce_yitiji-1); % 遥测总丢包数% 地面网口接口是否丢包,前后相减是否为1zhu_diubao_gnd_eth = diff(zhu_cnt_gnd_eth);zhu_diubao_gnd_eth(zhu_diubao_gnd_eth <= 0) = zhu_diubao_gnd_eth(zhu_diubao_gnd_eth <= 0) + 256; % 处理负数zhu_flag_diubao_gnd_eth = zhu_diubao_gnd_eth ~= 1; % 地面网口丢包时刻zhu_count_diubao_gnd_eth = sum(zhu_diubao_gnd_eth-1); % 地面网口丢包数% 遥控链路通断状态(大于0即可)zhu_state_yk_link = zhu_state_yaokong > 0;% 地面遥控指令是否连续(是否存在00)zhu_state_yk_zl = zhu_control_yaokong == 0;k=1;while zhu_state_yk_zl(k) == 1 && k < 500 % 清除错误的数值,容错前50个。zhu_state_yk_zl(k) = 0;k = k+1; endzhu_count_state_yk_zl = sum(zhu_state_yk_zl); % 遥控总丢包数zhu_flag_state_yk_zl = zhu_state_yk_zl ~= 0;% 遥控指令切换状态,切换计数器yk_zl_qiehuan = diff(state_yk_qie(:,1));% 角度负数处理zhu_angle_cabrage(zhu_angle_cabrage>327.67) = zhu_angle_cabrage(zhu_angle_cabrage>327.67) - 655.36; zhu_angle_roll(zhu_angle_roll>327.67) = zhu_angle_roll(zhu_angle_roll>327.67) - 655.36; zhu_angle_Heading(zhu_angle_Heading>327.67) = zhu_angle_Heading(zhu_angle_Heading>327.67) - 655.36; % 经纬度负数处理 比例尺换算zhu_longitude(zhu_longitude>8388607) = zhu_longitude(zhu_longitude>8388607) - 16777216;zhu_latitude(zhu_latitude>8388607) = zhu_latitude(zhu_latitude>8388607) - 16777216;zhu_longitude = zhu_longitude * 0.00005;zhu_latitude = zhu_latitude * 0.00005;% 轨迹与丢包图zhu_remove_eth = zhu_flag_diubao_yaoce_link-zhu_flag_diubao_gnd_eth;zhu_longitude_err = zhu_longitude(zhu_remove_eth==1);zhu_latitude_err = zhu_latitude(zhu_remove_eth==1);zhu_high_err = zhu_positiong_high(zhu_remove_eth==1);zhu_longitude_right = zhu_longitude(zhu_remove_eth==0);zhu_latitude_right = zhu_latitude(zhu_remove_eth==0);zhu_high_right = zhu_positiong_high(zhu_remove_eth==0);% 统计丢包数(网络、链路、遥测、遥控)FILENAMES(1) = 'main'; % 文件名称LOSS_YTJ(1) = zhu_count_diubao_yaoce_yitiji ; % 一体机丢包LOSS_RAD(1) = zhu_count_diubao_yaoce_link ; % 遥测链路丢包LOSS_ETH(1) = zhu_count_diubao_gnd_eth; % 以太网丢包LOSS_YK(1) = zhu_count_state_yk_zl; % 遥控丢包disp('如上图所示,网络丢'+string(LOSS_ETH(1))+'包,遥测链路丢'+ ...string(LOSS_RAD(1))+'包,一体机丢'+string(LOSS_YTJ(1))+ ...'包,遥控丢'+string(LOSS_YK(1))+'包。'); % 快速报告%% 副站数据处理% 遥测链路是否丢包,前后相减是否为1fu_diubao_yaoce_link = diff(fu_cnt_yaoce_link);fu_diubao_yaoce_link(fu_diubao_yaoce_link <= 0) = fu_diubao_yaoce_link(fu_diubao_yaoce_link <= 0) + 256; % 处理负数fu_flag_diubao_yaoce_link = fu_diubao_yaoce_link ~= 1; % 遥测链路丢包时刻fu_count_diubao_yaoce_link = sum(fu_diubao_yaoce_link-1); % 遥测链路丢包数% 遥测是否丢包,基于一体机,前后相减是否为1 fu_diubao_yaoce_yitiji = diff(fu_time_yitiji);fu_diubao_yaoce_yitiji(fu_diubao_yaoce_yitiji < 0) = fu_diubao_yaoce_yitiji(fu_diubao_yaoce_yitiji < 0) + 65536; % 处理负数fu_flag_diubao_yaoce_yitiji = fu_diubao_yaoce_yitiji ~= 1; % 遥测丢包时刻fu_count_diubao_yaoce_yitiji = sum(fu_diubao_yaoce_yitiji-1); % 遥测总丢包数% 地面网口接口是否丢包,前后相减是否为1fu_diubao_gnd_eth = diff(fu_cnt_gnd_eth);fu_diubao_gnd_eth(fu_diubao_gnd_eth <= 0) = fu_diubao_gnd_eth(fu_diubao_gnd_eth <= 0) + 256; % 处理负数fu_flag_diubao_gnd_eth = fu_diubao_gnd_eth ~= 1; % 地面网口丢包时刻fu_count_diubao_gnd_eth = sum(fu_diubao_gnd_eth-1); % 地面网口丢包数% 遥控链路通断状态(大于0即可)fu_state_yk_link = fu_state_yaokong > 0;% 地面遥控指令是否连续(是否存在00)fu_state_yk_zl = fu_control_yaokong == 0;k=1;while fu_state_yk_zl(k) == 1 && k < 500 % 清除错误的数值,容错前50个。fu_state_yk_zl(k) = 0;k = k+1; endfu_count_state_yk_zl = sum(fu_state_yk_zl); % 遥控总丢包数fu_flag_state_yk_zl = fu_state_yk_zl ~= 0;% 角度负数处理fu_angle_cabrage(fu_angle_cabrage>327.67) = fu_angle_cabrage(fu_angle_cabrage>327.67) - 655.36; fu_angle_roll(fu_angle_roll>327.67) = fu_angle_roll(fu_angle_roll>327.67) - 655.36; fu_angle_Heading(fu_angle_Heading>327.67) = fu_angle_Heading(fu_angle_Heading>327.67) - 655.36; % 经纬度负数处理 比例尺换算fu_longitude(fu_longitude>8388607) = fu_longitude(fu_longitude>8388607) - 16777216;fu_latitude(fu_latitude>8388607) = fu_latitude(fu_latitude>8388607) - 16777216;fu_longitude = fu_longitude * 0.00005;fu_latitude = fu_latitude * 0.00005;% 轨迹与丢包图fu_remove_eth = fu_flag_diubao_yaoce_link-fu_flag_diubao_gnd_eth;fu_longitude_err = fu_longitude(fu_remove_eth==1);fu_latitude_err = fu_latitude(fu_remove_eth==1);fu_high_err = fu_positiong_high(fu_remove_eth==1);fu_longitude_right = fu_longitude(fu_remove_eth==0);fu_latitude_right = fu_latitude(fu_remove_eth==0);fu_high_right = fu_positiong_high(fu_remove_eth==0);% 统计丢包数(网络、链路、遥测、遥控)FILENAMES(2) = 'slave'; % 文件名称LOSS_YTJ(2) = fu_count_diubao_yaoce_yitiji ; % 一体机丢包LOSS_RAD(2) = fu_count_diubao_yaoce_link ; % 遥测链路丢包LOSS_ETH(2) = fu_count_diubao_gnd_eth; % 以太网丢包LOSS_YK(2) = fu_count_state_yk_zl; % 遥控丢包disp('如上图所示,网络丢'+string(LOSS_ETH(2))+'包,遥测链路丢'+ ...string(LOSS_RAD(2))+'包,一体机丢'+string(LOSS_YTJ(2))+ ...'包,遥控丢'+string(LOSS_YK(2))+'包。'); % 快速报告[Angle_Antenna,Length,fuyang_test] = ...Antenna_direction(109.621197,40.847384,fu_longitude,fu_latitude,...fu_positiong_high,fu_angle_Heading); % 副站 仰角,距离,[Angle_Antenna_zhu,Length_zhu,fuyang_test_zhu] = ...Antenna_direction(109.621197,40.847384,zhu_longitude,zhu_latitude,...zhu_positiong_high,zhu_angle_Heading); % 主站 仰角,距离
%% 联合数据分析
% 遥控信号能量 & 主站遥控丢包
img = gcf;
clf(img);
hold on;
plot(zhu_signal_power,'r');plot([0,zhu_len_tele],[48,48],'linestyle','--'); % 大信号
plot([0,zhu_len_tele],[95,95],'linestyle','--'); % 大信号
plot([0,zhu_len_tele],[96,96],'linestyle','--'); % 中信号
plot([0,zhu_len_tele],[143,143],'linestyle','--'); % 中信号
plot([0,zhu_len_tele],[144,144],'linestyle','--'); % 小信号
plot([0,zhu_len_tele],[191,191],'linestyle','--'); % 小信号
plot(zhu_flag_state_yk_zl*150,'g'); % 遥控丢包title('遥控信号能量 & 主站遥控丢包');
legend('遥控信号能量','大信号上限','大信号下限', ...'中信号下限','中信号上限','小信号下限','小信号上限',...'遥控丢包','Location','NorthEastOutside');
hold off;
savefig(img,'1_遥控丢包_遥控能量zhu.fig');% 遥控信号能量 & 副站遥控丢包
img = gcf;
clf(img);
hold on;
plot(fu_signal_power,'r');plot([0,fu_len_tele],[48,48],'linestyle','--'); % 大信号
plot([0,fu_len_tele],[95,95],'linestyle','--'); % 大信号
plot([0,fu_len_tele],[96,96],'linestyle','--'); % 中信号
plot([0,fu_len_tele],[143,143],'linestyle','--'); % 中信号
plot([0,fu_len_tele],[144,144],'linestyle','--'); % 小信号
plot([0,fu_len_tele],[191,191],'linestyle','--'); % 小信号
plot(fu_flag_state_yk_zl*150,'g'); % 遥控丢包title('遥控信号能量 & 副站遥控丢包');
legend('遥控信号能量','大信号上限','大信号下限', ...'中信号下限','中信号上限','小信号下限','小信号上限',...'遥控丢包','Location','NorthEastOutside');
hold off;
savefig(img,'1_遥控丢包_遥控能量fu.fig');% 主站遥控丢包与飞行轨迹
clf(img);
subplot(1,2,1);
scatter3(zhu_longitude,zhu_latitude,zhu_positiong_high,10,"blue");
hold on;
scatter3( zhu_longitude(zhu_flag_state_yk_zl==1), ...zhu_latitude(zhu_flag_state_yk_zl==1), ...zhu_positiong_high(zhu_flag_state_yk_zl==1),100,"red");
ylim([40.75 40.95]);
xlim([109 109.7]);
zlim([1200 2000]);
xlabel("longitude");ylabel("latitude");zlabel("high");
title('靶弹飞行轨迹图 & 主站遥控丢包');
legend('飞行轨迹','遥控丢包','Location','NorthEastOutside');
% savefig(img,'1_2_轨迹与遥控丢包主站.fig');
% hold off;% 副站遥控丢包 与 飞行轨迹
% clf(img);
subplot(1,2,2);
scatter3(fu_longitude,fu_latitude,fu_positiong_high,10,"blue");
hold on;
scatter3( fu_longitude(fu_flag_state_yk_zl==1), ...fu_latitude(fu_flag_state_yk_zl==1), ...fu_positiong_high(fu_flag_state_yk_zl==1),100,"red");
ylim([40.75 40.95]);
xlim([109 109.7]);
zlim([1200 2000]);
xlabel("longitude");ylabel("latitude");zlabel("high");
title('靶弹飞行轨迹图 & 副站遥控丢包');
legend('飞行轨迹','遥控丢包','Location','NorthEastOutside');
savefig(img,'1_2_轨迹与遥控丢包主副站比较图.fig');
hold off;% 飞行(俯仰、滚动、航向)& 丢包时刻
% 飞行(经纬度、高度)& 丢包时刻
clf(img);
hold on;
plot(zhu_angle_cabrage);
plot(zhu_angle_roll);
plot(zhu_angle_Heading);
plot(zhu_flag_diubao_yaoce_link*150,'g--');
legend('俯仰角','滚动角','航向角','遥测丢包','Location','NorthEastOutside');
xlabel('时刻');ylabel("角度值");
title('主站:俯仰、滚动、航向 & 丢包图');
ylim([-180 180]);
hold off;
% print(img,'-dpng','-r800','2_1_飞行角度zhu.png');
savefig(img,'2_1_飞行角度zhu.fig'); clf(img);
hold off;
scatter3(zhu_longitude_right,zhu_latitude_right,zhu_high_right,10,"blue");
hold on;
scatter3(zhu_longitude_err,zhu_latitude_err,zhu_high_err,50,"red");
xlabel("longitude");ylabel("latitude");zlabel("high");
ylim([40.75 40.95]);
xlim([109 109.7]);
zlim([1200 2000]);
title('主站:飞行轨迹 & 丢包图');
hold off;
savefig(img,'2_2_轨迹与丢包zhu.fig'); clf(img);
hold on;
plot(fu_angle_cabrage);
plot(fu_angle_roll);
plot(fu_angle_Heading);
plot(fu_flag_diubao_yaoce_link*150,'g--');
legend('俯仰角','滚动角','航向角','遥测丢包','Location','NorthEastOutside');
title('副站:俯仰、滚动、航向 & 丢包图');
ylim([-180 180]);
hold off;
% print(img,'-dpng','-r800','2_1_飞行角度fu.png');
savefig(img,'2_1_飞行角度fu.fig'); clf(img);
hold off;
scatter3(fu_longitude_right,fu_latitude_right,fu_high_right,10,"blue");
hold on;
scatter3(fu_longitude_err,fu_latitude_err,fu_high_err,50,"red");
ylim([40.75 40.95]);
xlim([109 109.7]);
zlim([1200 2000]);
xlabel("longitude");ylabel("latitude");zlabel("high");
title('副站:飞行轨迹 & 丢包图');
hold off;
savefig(img,'2_2_轨迹与丢包fu.fig'); clf(img);
hold off;
scatter3(fu_longitude_right,fu_latitude_right,fu_high_right,1,"black");
hold on;
scatter3(fu_longitude_err,fu_latitude_err,fu_high_err,200,"red");
scatter3(zhu_longitude_err,zhu_latitude_err,zhu_high_err,50,"blue");
ylim([40.75 40.95]);
xlim([109 109.7]);
zlim([1200 2000]);
xlabel("longitude");ylabel("latitude");zlabel("high");
title('主副站:俯仰、滚动、航向 & 丢包图');
legend('轨迹图','副站丢包','主站丢包','Location','NorthEastOutside');
hold off;
savefig(img,'2_3_主副站轨迹与丢包.fig'); % 副站 丢包时刻的三个角度信息
fu_diubao_index = find(fu_remove_eth==1);
fu_diubao_pitch = [];
fu_diubao_yaw = [];
fu_diubao_roll = [];
fu_diubao_angle = [];
fu_diubao_jin = [];
fu_diubao_wei = [];
fu_diubao_gao = [];
j=1;
for i = fu_diubao_index'fu_diubao_pitch(j) = fu_angle_cabrage(i);fu_diubao_yaw(j) = fu_angle_Heading(i);fu_diubao_roll(j) = fu_angle_roll(i);fu_diubao_angle(j) = Angle_Antenna(i); fu_diubao_jin(j) = fu_longitude(i);fu_diubao_wei(j) = fu_latitude(i);fu_diubao_gao(j) = fu_positiong_high(i);j=j+1;
end% 主站 丢包时刻的三个角度信息
zhu_diubao_index = find(zhu_remove_eth==1);
zhu_diubao_pitch = [];
zhu_diubao_yaw = [];
zhu_diubao_roll = [];
zhu_diubao_angle = [];
j=1;
for i = zhu_diubao_index'zhu_diubao_pitch(j) = zhu_angle_cabrage(i);zhu_diubao_yaw(j) = zhu_angle_Heading(i);zhu_diubao_roll(j) = zhu_angle_roll(i);zhu_diubao_angle(j) = Angle_Antenna_zhu(i); j=j+1;
end% 副站 全数据点分析(包含起飞和降落阶段)
fu_all_analysis_pitch = fu_angle_cabrage(fu_remove_eth==1);
fu_all_analysis_yaw = fu_angle_Heading(fu_remove_eth==1);
fu_all_analysis_roll = fu_angle_roll(fu_remove_eth==1);
scatter3(fu_all_analysis_pitch,fu_all_analysis_yaw,fu_all_analysis_roll,100,"red");
xlabel("俯仰角 Pitch");ylabel("航向角 Yaw");zlabel("滚动角 Roll");
title('副站:全过程的俯仰、滚动、航向 & 丢包图');
savefig(img,'3_1_全数据姿态与丢包.fig'); % 副站 飞行数据点分析
fu_fly_pitch = fu_angle_cabrage(32727:148411);
fu_fly_yaw = fu_angle_Heading(32727:148411);
fu_fly_roll = fu_angle_roll(32727:148411);
fu_fly_remove= fu_remove_eth(32727:148411);
fu_fly_analysis_pitch = fu_fly_pitch(fu_fly_remove==1);
fu_fly_analysis_yaw = fu_fly_yaw(fu_fly_remove==1);
fu_fly_analysis_roll = fu_fly_roll(fu_fly_remove==1);
scatter3(fu_fly_analysis_pitch,fu_fly_analysis_yaw,fu_fly_analysis_roll,200,"blue");
xlabel("俯仰角 Pitch");ylabel("航向角 Yaw");zlabel("滚动角 Roll");
title('副站:飞行过程的俯仰、滚动、航向 & 丢包图');
savefig(img,'3_2_飞行数据与丢包.fig'); % 主站 全数据点分析(包含起飞和降落阶段)
zhu_all_analysis_pitch = zhu_angle_cabrage(zhu_remove_eth==1);
zhu_all_analysis_yaw = zhu_angle_Heading(zhu_remove_eth==1);
zhu_all_analysis_roll = zhu_angle_roll(zhu_remove_eth==1);
scatter3(zhu_all_analysis_pitch,zhu_all_analysis_yaw,zhu_all_analysis_roll,100,"red");
xlabel("俯仰角 Pitch");ylabel("航向角 Yaw");zlabel("滚动角 Roll");
title('主站:全过程的俯仰、滚动、航向 & 丢包图');
savefig(img,'3_3_全数据姿态与丢包.fig'); % 主站 飞行数据点分析
zhu_fly_pitch = zhu_angle_cabrage(32727:148411);
zhu_fly_yaw = zhu_angle_Heading(32727:148411);
zhu_fly_roll = zhu_angle_roll(32727:148411);
zhu_fly_remove= zhu_remove_eth(32727:148411);
zhu_fly_analysis_pitch = zhu_fly_pitch(zhu_fly_remove==1);
zhu_fly_analysis_yaw = zhu_fly_yaw(zhu_fly_remove==1);
zhu_fly_analysis_roll = zhu_fly_roll(zhu_fly_remove==1);
scatter3(zhu_fly_analysis_pitch,zhu_fly_analysis_yaw,zhu_fly_analysis_roll,200,"blue");
xlabel("俯仰角 Pitch");ylabel("航向角 Yaw");zlabel("滚动角 Roll");
title('主站:飞行过程的俯仰、滚动、航向 & 丢包图');
savefig(img,'3_4_飞行数据与丢包.fig'); % 主副站 全数据点分析(包含起飞和降落阶段)
scatter3(fu_all_analysis_pitch,fu_all_analysis_yaw,fu_all_analysis_roll,300,"red");
hold on;
scatter3(zhu_all_analysis_pitch,zhu_all_analysis_yaw,zhu_all_analysis_roll,100,"blue");
xlabel("俯仰角 Pitch");ylabel("航向角 Yaw");zlabel("滚动角 Roll");
legend('副站丢包','主站丢包','Location','NorthEastOutside');
title('主副站:全过程的俯仰、滚动、航向 & 丢包图');
savefig(img,'3_5_全数据姿态与丢包.fig');
hold off;% 主副站 飞行数据点分析
scatter3(fu_fly_analysis_pitch,fu_fly_analysis_yaw,fu_fly_analysis_roll,300,"red");
hold on;
scatter3(zhu_fly_analysis_pitch,zhu_fly_analysis_yaw,zhu_fly_analysis_roll,100,"blue");
xlabel("俯仰角 Pitch");ylabel("航向角 Yaw");zlabel("滚动角 Roll");
legend('副站丢包','主站丢包','Location','NorthEastOutside');
title('主副站:飞行过程的俯仰、滚动、航向 & 丢包图');
savefig(img,'3_6_飞行数据与丢包.fig');
hold off;% 副站 天线方向图
plot(fu_diubao_roll,fu_diubao_angle,'.');
xlabel("滚动角 Roll");ylabel("天线方向图角");
title('副站 天线方向图');
savefig(img,'4_1_副站天线方向图.fig'); % 副站 天线仰角与丢包 || 副站天线 俯仰角20度,10度
clf(img);
hold on;
plot(find(fu_remove_eth==1),fuyang_test(fu_remove_eth==1),'rs','LineWidth',2,'MarkerSize',5);
plot(find(fu_remove_eth==0),fuyang_test(fu_remove_eth==0),'b');
plot([0,length(fu_remove_eth)],[10,10],'linestyle','--','LineWidth',2); % 天线波束范围
legend('丢包','不丢包','天线范围','Location','NorthEastOutside');
xlabel("飞行过程");ylabel("角度");
title('副站:地面与靶弹的俯仰角 丢包示意图');
savefig(img,'4_2_靶弹与副站天线仰角丢包示意图.fig');
hold off;% 主站 天线方向图
plot(zhu_diubao_roll,zhu_diubao_angle,'.');
xlabel("滚动角 Roll");ylabel("天线方向图角");
title('主站 天线方向图');
savefig(img,'4_3_主站天线方向图.fig');
hold off;% 主站 天线仰角与丢包 || 主站天线 H波束宽度33度,一半有16.5度 , 上翘9度,和起来有 25.5度 相对副站好
clf(img);
hold on;
plot(find(zhu_remove_eth==1),fuyang_test_zhu(zhu_remove_eth==1),'rs','LineWidth',2,'MarkerSize',5);
plot(find(zhu_remove_eth==0),fuyang_test_zhu(zhu_remove_eth==0),'b');
plot([0,length(zhu_remove_eth)],[25.5,25.5],'linestyle','--','LineWidth',2); % 天线波束范围
legend('丢包','不丢包','天线范围','Location','NorthEastOutside');
xlabel("飞行过程");ylabel("角度");
title('主站:地面与靶弹的俯仰角 丢包示意图');
savefig(img,'4_4_靶弹与主站天线仰角丢包示意图.fig'); %% 数据统计与导出
FILENAMES = FILENAMES';
LOSS_YTJ = LOSS_YTJ';
LOSS_RAD = LOSS_RAD';
LOSS_ETH = LOSS_ETH';
LOSS_YK = LOSS_YK';writetable(table(FILENAMES,LOSS_YTJ,LOSS_RAD,LOSS_ETH,LOSS_YK, ...'VariableNames',["FILENAMES","LOSS_YTJ","LOSS_RAD","LOSS_ETH", ..."LOSS_YK"]),'丢包数据统计(一体机丢包-遥测链路丢包-地面网口丢包-遥控丢包).csv');fu_diubao_pitch = fu_diubao_pitch';
fu_diubao_yaw = fu_diubao_yaw';
fu_diubao_roll = fu_diubao_roll';
fu_diubao_angle = fu_diubao_angle';
fu_diubao_jin = fu_diubao_jin';
fu_diubao_wei = fu_diubao_wei';
fu_diubao_gao = fu_diubao_gao';writetable(table(fu_diubao_index,fu_diubao_pitch,fu_diubao_yaw,fu_diubao_roll, ...fu_diubao_angle, fu_diubao_jin,fu_diubao_wei, fu_diubao_gao, ...'VariableNames',["index","pitch","yaw","roll","angle","jin","wei","gao" ...]),'副站飞行过程中丢包与角度分析.csv');toc;%% 计算所需的函数
function UTC = ConvertNum2UTC(x)len = length(x);for i = 1:lenh = fix(x(i)/1000/3600);m = fix((x(i)/1000-h*3600)/60);s = fix(x(i)/1000-h*3600-m*60);UTC(i) = string(h)+"h"+string(m)+"m"+string(s)+"s";endUTC=UTC';
endfunction Write_UTC_control(control,change,UTC,filename)len = length(change);j=1;LIST_CONTROL = [""];LIST_UTC = [""];LIST_INDEX = [];for i=1:lenif(change(i)) == 1LIST_CONTROL(j) = dec2hex(control(i+1));LIST_UTC(j) = UTC(i+1);LIST_INDEX(j) = i;j=j+1;endendLIST_CONTROL = LIST_CONTROL';LIST_UTC = LIST_UTC';LIST_INDEX = LIST_INDEX';writetable(table(LIST_INDEX,LIST_CONTROL,LIST_UTC,'VariableNames',["index","control","utc"]),filename+'/指令切换与UTC时间.csv');
endfunction [Angle_Antenna,Length,fuyang_test] = Antenna_direction(local_j,local_w,aim_j,aim_w,high,yaw)%Angle_Antenna = Antenna_direction(109.621197,40.847384,fu_longitude,fu_latitude,fu_positiong_high,fu_angle_Heading)earthR = 6371000000 ;%单位厘米local_j_hudu= local_j*pi/180;%角度与弧度local_w_hudu= local_w*pi/180;%角度与弧度aim_j_hudu = aim_j.*pi/180 ;%角度与弧度aim_w_hudu = aim_w.*pi/180 ;%角度与弧度V1=sin(aim_j_hudu-local_j_hudu).*cos(aim_w_hudu);V2=cos(local_w_hudu).*sin(aim_w_hudu) -sin(local_w_hudu).*cos(aim_w_hudu).*cos(aim_j_hudu-local_j_hudu);AB2=sin((local_w_hudu-aim_w_hudu)/2).*sin((local_w_hudu-aim_w_hudu)/2) + cos(local_w_hudu).*cos(aim_w_hudu).*sin((local_j_hudu-aim_j_hudu)/2).*sin((local_j_hudu-aim_j_hudu)/2);Length=2*earthR.*asin(sqrt(AB2))/1000; %单位厘米 直线距离 Angle=atan2(V1,V2).*180./pi; %该单位是-pi至pi,正值不变,需要将负值加上360°。而UB482是0至360°与真北的夹角fuyang_test =asin( abs((high - 1284))./sqrt((high - 1284).^2 + (Length).^2))./pi.*180;%假设地面天线架设5米% 改变航向角的真北角定义 原始定义:顺时针为负。 % 计算天线方向图Angles = - yaw - Angle;% 转化为0到360Angles_360 = Angles;for i = 1:length(Angles_360)if(Angles_360(i) < 0)Angles_360(i) = Angles_360(i) + 360;elseif(Angles_360(i) > 360)Angles_360(i) = Angles_360(i) - 360;elseAngles_360(i) = Angles_360(i);endend% 转化为 -180~+180Angles_zf_180 = Angles_360;for i = 1:length(Angles_zf_180)if(Angles_zf_180(i) > 180)Angles_zf_180(i) = Angles_zf_180(i) - 360;elseAngles_zf_180(i) = Angles_zf_180(i);endend% 转化为天线方向图Angle_Antenna = Angles_zf_180;for i = 1:length(Angle_Antenna)if(Angle_Antenna(i) >= 0)Angle_Antenna(i) = Angle_Antenna(i) - 180;elseAngle_Antenna(i) = Angle_Antenna(i) + 180;endend
end
function plot_k_means(pitch,yaw,roll,n)[idx,C] = kmeans([pitch;yaw;roll],n);disp(size(idx))for i = 1:nscatter3(pitch(idx==i),yaw(idx==i),roll(idx==i),".");hold on;endhold off;
end