【2243】module_param.m_无损检测小白白的博客-程序员秘密

技术标签: matlab  AWR2243  开发语言  

cascade_MIMO_signalProcessing

% 处理原始ADC数据的顶级主测试链。处理链包括adc数据校准模块、量程FFT模块、多普勒FFT
模块,CFAR模块,DOA模块。每个模块在链中实际使用之前都首先初始化。

%  Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
%
%
%   Redistribution and use in source and binary forms, with or without
%   modification, are permitted provided that the following conditions
%   are met:
%
%     Redistributions of source code must retain the above copyright
%     notice, this list of conditions and the following disclaimer.
%
%     Redistributions in binary form must reproduce the above copyright
%     notice, this list of conditions and the following disclaimer in the
%     documentation and/or other materials provided with the
%     distribution.
%
%     Neither the name of Texas Instruments Incorporated nor the names of
%     its contributors may be used to endorse or promote products derived
%     from this software without specific prior written permission.
%
%   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
%   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
%   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
%   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
%   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
%   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
%   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
%   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
%   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
%   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
%   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%
%

% cascade_MIMO_signalProcessing.m
%
% Top level main test chain to process the raw ADC data. The processing chain including adc data calibration module, range FFT module, DopplerFFT
% module, CFAR module, DOA module. Each module is first initialized before actually used in the chain.
% 处理原始ADC数据的顶级主测试链。处理链包括adc数据校准模块、量程FFT模块、多普勒FFT
% 模块,CFAR模块,DOA模块。每个模块在链中实际使用之前都首先初始化。

clearvars
close all

PLOT_ON = 1;              % 1: turn plot on; 0: turn plot off   1:开启;0:关闭
LOG_ON = 1;               % 1: log10 scale; 0: linear scale     1: log10刻度;0:线性范围
% numFrames_toRun = 10;   %要运行的帧数,可以少于保存在原始数据中的帧数 number of frame to run, can be less than the frame saved in the raw data
SAVEOUTPUT_ON = 0;
PARAM_FILE_GEN_ON = 1;
DISPLAY_RANGE_AZIMUTH_DYNAMIC_HEATMAP = 1 ;     % Will make things slower   显示范围方位动态热图 0不显示、1显示
dataPlatform = 'TDA2'

%% get the input path and testList 获取输入路径和testList   
pro_path = getenv('CASCADE_SIGNAL_PROCESSING_CHAIN_MIMO'); % getenv的这个调用返回一个空字符数组;getenv会返回一些环境变量
% input_path = strcat(pro_path,'\main\cascade\input\');      % strcat 横向连接字符串
input_path = strcat(pro_path,'input\');      % strcat 横向连接字符串
testList = strcat(input_path,'testList.txt');
%path for input folder 输入文件夹路径
fidList = fopen(testList,'r');
testID = 1;

while ~feof(fidList)                                        % 表示若未读到文件末尾,则继续循环
    
    %% get each test vectors within the test list     获取测试列表中的每个测试向量
    % test data file name 测试数据文件名  采集的数据
    dataFolder_test = fgetl(fidList);    % fgetl()读取每一行
   
    %calibration file name 校准文件名称
    dataFolder_calib = fgetl(fidList);
    
    %module_param_file 定义初始化每个信号处理的参数
    %module
    module_param_file = fgetl(fidList);
    
    %parameter file name for the test测试的参数文件名
    %生成测试参数的.m文件,放入 input_path 路径下
    pathGenParaFile = [input_path,'test',num2str(testID), '_param.m'];  % num2str()把数值转换成字符串
    %important to clear the same.m file, since Matlab does not clear cache automatically
    %清除同样的文件,因为Matlab不会自动清除缓存
    clear(pathGenParaFile);
    
    %generate parameter file for the test to run 生成运行测试的参数文件
    if PARAM_FILE_GEN_ON == 1    
        parameter_file_gen_json(dataFolder_test, dataFolder_calib, module_param_file, pathGenParaFile, dataPlatform);
        
    end
    
    %load calibration parameters  校准参数
    load(dataFolder_calib)        %load将文件变量加载到工作区中
    
    % simTopObj is used for top level parameter parsing and data loading and saving 
    % 用于顶级参数解析以及数据加载和保存
    simTopObj           = simTopCascade('pfile', pathGenParaFile);
    % 校准级联
    calibrationObj      = calibrationCascade('pfile', pathGenParaFile, 'calibrationfilePath', dataFolder_calib);
    rangeFFTObj         = rangeProcCascade('pfile', pathGenParaFile);
    DopplerFFTObj       = DopplerProcClutterRemove('pfile', pathGenParaFile);
    detectionObj        = CFAR_CASO('pfile', pathGenParaFile);
    DOAObj              = DOACascade('pfile', pathGenParaFile);
    
    % get system level variables
    %获取系统级变量
    platform            = simTopObj.platform;
    numValidFrames      = simTopObj.totNumFrames;
    
    cnt = 1;
    frameCountGlobal = 0;
    
    
   % Get Unique File Idxs in the "dataFolder_test"    在“dataFolder_test”中获取唯一的文件Idxs
   [fileIdx_unique] = getUniqueFileIdx(dataFolder_test);
    
    for i_file = 1:(length(fileIdx_unique))
        
       % Get File Names for the Master, Slave1, Slave2, Slave3   
      [fileNameStruct]= getBinFileNames_withIdx(dataFolder_test, fileIdx_unique{i_file});        
       
      %pass the Data File to the calibration Object 将数据文件传递给校准对象
      calibrationObj.binfilePath = fileNameStruct;
        
      %检测结果
      detection_results = [];  
        
       % Get Valid Number of Frames 获取有效的帧数
       [numValidFrames dataFileSize] = getValidNumFrames(fullfile(dataFolder_test, fileNameStruct.masterIdxFile));
        %intentionally skip the first frame due to TDA2  故意跳过第一帧,因为TDA2
       
        for frameIdx = 2:1:numValidFrames;                      % numFrames_toRun运行的帧数
            tic                                                 % ic表示计时的开始,toc表示计时的结束。    
            %read and calibrate raw ADC data    
            %读取并校准原始ADC数据
            calibrationObj.frameIdx = frameIdx;
            frameCountGlobal = frameCountGlobal+1
            adcData = datapath(calibrationObj);  % calibrationCascade模块的datapath功能,该功能使用校准来校准ADC数据
            
            % RX Channel re-ordering  RX通道重新排序
                adcData = adcData(:,:,calibrationObj.RxForMIMOProcess,:);            
            
            %only take TX and RXs required for MIMO data analysis  只接收MIMO数据分析所需的TX和RXs
            % adcData = adcData
            
            if mod(frameIdx, 10)==1         % b = mod(a,m) 返回用 m 除 a 后的余数
                fprintf('Processing %3d frame...\n', frameIdx);
            end
            
            
            %perform 2D FFT  进行二维FFT
            rangeFFTOut = [];
            DopplerFFTOut = [];
            
            for i_tx = 1: size(adcData,4)
                % range FFT
                rangeFFTOut(:,:,:,i_tx)     = datapath(rangeFFTObj, adcData(:,:,:,i_tx));
                
                % Doppler FFT
                DopplerFFTOut(:,:,:,i_tx)   = datapath(DopplerFFTObj, rangeFFTOut(:,:,:,i_tx));
                
            end
            
  
            % CFAR done along only TX and RX used in MIMO array 
            %仅沿MIMO阵列中使用的TX和RX执行恒虚警
            DopplerFFTOut = reshape(DopplerFFTOut,size(DopplerFFTOut,1), size(DopplerFFTOut,2), size(DopplerFFTOut,3)*size(DopplerFFTOut,4));
            
            %detection检测
            sig_integrate = 10*log10(sum((abs(DopplerFFTOut)).^2,3) + 1);
                        % .*表示两个矩阵对应元素相乘
            detection_results = datapath(detectionObj, DopplerFFTOut);
            detection_results_all{cnt} =  detection_results;
            
            detect_all_points = [];
            for iobj = 1:length(detection_results)
                detect_all_points (iobj,1)=detection_results(iobj).rangeInd+1;
                detect_all_points (iobj,2)=detection_results(iobj).dopplerInd_org+1;
                detect_all_points (iobj,4)=detection_results(iobj).estSNR;
            end
            
            if PLOT_ON
                figure(1);
                set(gcf,'units','normalized','outerposition',[0 0 1 1])     % gcf 返回当前Figure 对象的句柄值           
                subplot(2,2,1)               
                plot((1:size(sig_integrate,1))*detectionObj.rangeBinSize, sig_integrate(:,size(sig_integrate,2)/2+1),'g','LineWidth',4);
                hold on; 
                grid on
                for ii=1:size(sig_integrate,2)
                    plot((1:size(sig_integrate,1))*detectionObj.rangeBinSize, sig_integrate(:,ii));
                    hold on; 
                    grid on
                    if ~isempty(detection_results)
                        ind = find(detect_all_points(:,2)==ii);  %find查找非零元素的索引和值
                        if (~isempty(ind))
                            rangeInd = detect_all_points(ind,1);
                            plot(rangeInd*detectionObj.rangeBinSize, sig_integrate(rangeInd,ii),'o','LineWidth',2,...
                                'MarkerEdgeColor','k',...
                                'MarkerFaceColor',[.49 1 .63],...
                                'MarkerSize',6);
                        end
                    end
                end
                
                %title(['FrameID: ' num2str(cnt)]);
                xlabel('Range(m)');
                ylabel('Receive Power (dB)')
                title(['Range Profile(zero Doppler - thick green line): frameID ' num2str(frameIdx)]);
                hold off;
                subplot(2,2,2);
                %subplot_tight(2,2,2,0.1)
                imagesc((sig_integrate))
                c = colorbar;
                c.Label.String = 'Relative Power(dB)';
                title(' Range/Velocity Plot');
                pause(0.01)
            end
            
            angles_all_points = [];
            xyz = [];
            %if 0
            if ~isempty(detection_results)
                % DOA, the results include detection results + angle estimation results.
                % access data with angleEst{frame}(objectIdx).fieldName
                angleEst = datapath(DOAObj, detection_results);
                
                if length(angleEst) > 0
                    for iobj = 1:length(angleEst)
                        angles_all_points (iobj,1:2)=angleEst(iobj).angles(1:2);
                        angles_all_points (iobj,3)=angleEst(iobj).estSNR;
                        angles_all_points (iobj,4)=angleEst(iobj).rangeInd;
                        angles_all_points (iobj,5)=angleEst(iobj).doppler_corr;
                        angles_all_points (iobj,6)=angleEst(iobj).range;
                        %switch left and right, the azimuth angle is flipped左右切换,方位角翻转
                        xyz(iobj,1) = angles_all_points (iobj,6)*sind(angles_all_points (iobj,1)*-1)*cosd(angles_all_points (iobj,2));
                        xyz(iobj,2) = angles_all_points (iobj,6)*cosd(angles_all_points (iobj,1)*-1)*cosd(angles_all_points (iobj,2));
                        %switch upside and down, the elevation angle is flipped
                        xyz(iobj,3) = angles_all_points (iobj,6)*sind(angles_all_points (iobj,2)*-1);
                        xyz(iobj,4) = angleEst(iobj).doppler_corr;
                        xyz(iobj,9) = angleEst(iobj).dopplerInd_org;
                        xyz(iobj,5) = angleEst(iobj).range;
                        xyz(iobj,6) = angleEst(iobj).estSNR;
                        xyz(iobj,7) = angleEst(iobj).doppler_corr_overlap;
                        xyz(iobj,8) = angleEst(iobj).doppler_corr_FFT;
                        
                    end
                    angles_all_all{cnt} = angles_all_points;
                    xyz_all{cnt}  = xyz;
                    maxRangeShow = detectionObj.rangeBinSize*rangeFFTObj.rangeFFTSize;
                    %tic
                    if PLOT_ON
                        moveID = find(abs(xyz(:,4))>=0);
                        subplot(2,2,4);                        
                        
                         if cnt==1
                             scatter3(xyz(moveID,1),xyz(moveID,2),xyz(moveID,3),45,(xyz(moveID,4)),'filled');% 填充图
                        else
%                              yz = [xyz_all{cnt}; xyz_all{cnt-1}];
%                              scatter3(xyz(moveID,1),xyz(moveID,2),xyz(moveID,3),45,(xyz(moveID,4)),'filled');
                        end
                        
                        c = colorbar;
                        c.Label.String = 'velocity (m/s)';                        
                        grid on;
                        
                        xlim([-20 20])
                        ylim([1 maxRangeShow])
                        %zlim([-4 4])
                        zlim([-5 5])
                        xlabel('X (m)')
                        ylabel('y (m)')
                        zlabel('Z (m)')                        
                        
                        view([-9 15])                        
                        title(' 3D point cloud');
                        
                        %plot range and azimuth heatmap绘图范围和方位热图
                        subplot(2,2,3)
                        STATIC_ONLY = 1;
                        minRangeBinKeep =  5;
                        rightRangeBinDiscard =  20;
                        [mag_data_static(:,:,frameCountGlobal) mag_data_dynamic(:,:,frameCountGlobal) y_axis x_axis]= plot_range_azimuth_2D(detectionObj.rangeBinSize, DopplerFFTOut,...
                            length(calibrationObj.IdTxForMIMOProcess),length(calibrationObj.RxForMIMOProcess), ...
                            detectionObj.antenna_azimuthonly, LOG_ON, STATIC_ONLY, PLOT_ON, minRangeBinKeep, rightRangeBinDiscard);
                        title('range/azimuth heat map static objects')
                       
                        
    if (DISPLAY_RANGE_AZIMUTH_DYNAMIC_HEATMAP)                   
    figure(2)
    subplot(121);
    surf(y_axis, x_axis, (mag_data_static(:,:,frameCountGlobal)).^0.4,'EdgeColor','none');
    view(2);
    xlabel('meters');    ylabel('meters')
    title({'Static Range-Azimuth Heatmap',strcat('Current Frame Number = ', num2str(frameCountGlobal))})
    
    subplot(122);
    surf(y_axis, x_axis, (mag_data_dynamic(:,:,frameCountGlobal)).^0.4,'EdgeColor','none');
    view(2);    
    xlabel('meters');    ylabel('meters')
    title('Dynamic HeatMap')
    end
    pause(0.1) 

     
                    end
                    
                end
                
            end
                             
            cnt = cnt + 1;    
       toc    
        end
        
        
    end
    
    ind = strfind(dataFolder_test, '\');
    testName = dataFolder_test(ind(end-1)+1:(ind(end)-1));
    if SAVEOUTPUT_ON == 1
        save(['.\main\cascade\output\newOutput_',testName,'.mat'],'angles_all_all', 'detection_results_all','xyz_all');
    end
    testID = testID + 1;
    
end

module_param.m

%包含用于信号处理的每个模块的初始参数列表,包括simTopCascade、calibration、rangeFFT、DopplerFFT、CFAR、DOA模块。重要的是要知道,每个参数都需要定义为moudleName\u parameterName,parameterName在相应的模块中定义。在更改此文件之前,用户需要知道每个模块具有哪些参数。

%  Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ 
%  
%  
%   Redistribution and use in source and binary forms, with or without 
%   modification, are permitted provided that the following conditions 
%   are met:
%  
%     Redistributions of source code must retain the above copyright 
%     notice, this list of conditions and the following disclaimer.
%  
%     Redistributions in binary form must reproduce the above copyright
%     notice, this list of conditions and the following disclaimer in the 
%     documentation and/or other materials provided with the   
%     distribution.
%  
%     Neither the name of Texas Instruments Incorporated nor the names of
%     its contributors may be used to endorse or promote products derived
%     from this software without specific prior written permission.
%  
%   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
%   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
%   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
%   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
%   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
%   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
%   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
%   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
%   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
%   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
%   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%  
% 

% module_param.m
%  
% Contains a list of inital parameters for each modules used for signal
% processing, including modules of simTopCascade, calibration, rangeFFT, DopplerFFT, CFAR, DOA
% it is important to know that each parameter needs to be defined as
% moudleName_parameterName, the parameterName is defined in the
% corresponding module. Users need to know what parameters each module have
% before change this file.
%包含用于信号处理的每个模块的初始参数列表,包括simTopCascade、calibration、rangeFFT、DopplerFFT、CFAR、DOA模块。
%重要的是要知道,每个参数都需要定义为moudleName\u parameterName,parameterName在相应的模块中定义。
%在更改此文件之前,用户需要知道每个模块具有哪些参数。

platform = 'TI_4Chip_CASCADE';

%% fixed antenna ID and postion values for TI 4-chip cascade board. Should not be changed if user is based on TI board
%%TI 4芯片级联板的固定天线ID和位置值。如果用户基于TI板,则不应更改
% % Legacy Format TDA
%传统格式TDA
% TI_Cascade_TX_position_azi = [0 4 8 12 16 20 24 28 32 9 10 11];%12 TX antenna azimuth position on TI 4-chip cascade EVM
% TI_Cascade_TX_position_ele = [0 0 0 0 0 0 0 0 0 1 4 6];%12 TX antenna elevation position on TI 4-chip cascade EVM

% New Format TDA
% 新格式 TDA
% TI 4芯片级联EVM上的TX天线方位角位置
TI_Cascade_TX_position_azi = [11 10 9 32 28 24 20 16 12 8 4 0 ];%12 TX antenna azimuth position on TI 4-chip cascade EVM
%TI 4芯片级联EVM上的12 TX天线仰角位置
TI_Cascade_TX_position_ele = [6 4 1 0 0 0 0 0 0 0 0 0];%12 TX antenna elevation position on TI 4-chip cascade EVM

% Legacy RX channel mapping  传统RX信道映射
%TI_Cascade_RX_position_azi = [42:-1:39 3:-1:0 7:-1:4 53:-1:50 ];%16 RX antenna azimuth position on TI 4-chip cascade EVM
% TI_Cascade_RX_position_azi = [0:3 11:14 50:53 46:49 ];
TI_Cascade_RX_position_ele = zeros(1,16);%16 RX antenna elevation position on TI 4-chip cascade EVM
% TI_Cascade_RX_ID = [1 2 3 4 5 6 7 8 13 14 15 16 9 10 11 12]; %RX channel order on TI 4-chip cascade EVM

% Changed for the new Data format  更改为新的数据格式
TI_Cascade_RX_position_azi = [ 11:14 50:53 46:49 0:3  ];
%TI 4芯片级联EVM上的RX信道顺序
TI_Cascade_RX_ID = [13 14 15 16 1 2 3 4 9 10 11 12 5 6 7 8 ]; %RX channel order on TI 4-chip cascade EVM
%天线距离就是为这个频率设计的
TI_Cascade_Antenna_DesignFreq = 76.8; % antenna distance is designed for this frequency

%% constants   常数
speedOfLight        = 3e8;
% 比例因子
scaleFactor         = [0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625, 0.001953125, 0.0009765625, 0.00048828125]*4;

%% define TX/RX antennas used for virtual array analysis. It can be a subset of the antennas enabled in data capture phase
%TxForMIMOProcess defines antenna TD used for TDM MIMO processing, can
%be a sub set of TxToEnable; CANNOT be channels that not enabled in TxToEnable
%%定义用于虚拟阵列分析的收发天线。它可以是在数据捕获阶段启用的天线的子集
%TXformoProcess定义了用于TDM MIMO处理的天线TD,可以是TxToEnable的子集;不能是未在TxToEnable中启用的通道
TxForMIMOProcess = TxToEnable;  
%TxForMIMOProcess = [1:9  ];
[IdTxForMIMOProcess ia ib] = intersect(TxForMIMOProcess, TxToEnable,'stable' );
if length(IdTxForMIMOProcess)~= length(TxForMIMOProcess)
    error('TX channel used for processing is not valid')
    
end
%使用所有16个RX,用户还可以选择RX的子集进行MIMO数据分析
RxForMIMOProcess = TI_Cascade_RX_ID; %using all 16 RXs, user can also choose subset of RXs for MIMO data analysis
%RxForMIMOProcess = [1:8];
%TX方位天线坐标
D_TX = TI_Cascade_TX_position_azi(TxToEnable(ib)); %TX azimuth antenna coordinates 
%TX仰角天线坐标
D_TX_ele = TI_Cascade_TX_position_ele(TxToEnable(ib));%TX elevation antenna coordinates
%RX方位天线坐标
D_RX = TI_Cascade_RX_position_azi(RxForMIMOProcess); %RX azimuth antenna coordinate
%RX仰角天线坐标
D_RX_ele = TI_Cascade_RX_position_ele(RxForMIMOProcess);%RX elevation antenna coordinate

%draw the virtual array
%绘制虚拟阵列
plotArray = 0;
RX_id_tot = [];
RX_id_tot_ele = [];
if plotArray == 1
    figure(1);
end
for ii = 1:length(D_TX)
    RX_id_new = D_RX + sum(D_TX(ii));
    RX_id_tot = [RX_id_tot RX_id_new];
    
    RX_id_new_ele = D_RX_ele + D_TX_ele(ii);
    RX_id_tot_ele = [RX_id_tot_ele RX_id_new_ele];
    if plotArray == 1
        plot(RX_id_new,RX_id_new_ele,'o');grid on; hold on
        ylim([-8 8])
    end
end
D(:,1) = RX_id_tot;
D(:,2) = RX_id_tot_ele;


%% derived parameters
%%导出参数
DopplerFFTSize = 2^(ceil(log2(nchirp_loops)));
numChirpsPerFrame = nchirp_loops*numChirpsInLoop;%nchirp_loops*numTxAnt;
chirpRampTime       = numADCSample/adcSampleRate;
chirpBandwidth      = chirpSlope * chirpRampTime; % Hz
chirpInterval       = chirpRampEndTime + chirpIdleTime;
carrierFrequency    = startFreqConst +  (adcStartTimeConst + chirpRampTime/2)*chirpSlope; % Hz center frequency
lambda              = speedOfLight/carrierFrequency;
maximumVelocity     = lambda / (chirpInterval*4) ; % m/s
maxRange            = speedOfLight*adcSampleRate*chirpRampTime/(2*chirpBandwidth);
numSamplePerChirp   = round(chirpRampTime*adcSampleRate);
rangeFFTSize        = 2^(ceil(log2(numSamplePerChirp)));
numChirpsPerVirAnt  = nchirp_loops;
numVirtualRxAnt     = length(TxForMIMOProcess) * length(RxForMIMOProcess) ;
rangeResolution     = speedOfLight/2/chirpBandwidth;
rangeBinSize        = rangeResolution*numSamplePerChirp/rangeFFTSize;
velocityResolution  = lambda / (2*nchirp_loops * chirpInterval*numTxAnt);
velocityBinSize     = velocityResolution*numChirpsPerVirAnt/DopplerFFTSize;


%% simTopCascade parameters
simTopCascade_inputDataSource          = 'bin'; % choose from 'mat','bin','gen'
simTopCascade_enable      = 1;
simTopCascade_outputDataSavingEnable   = 0;
simTopCascade_outputDataFileName       = [];
simTopCascade_totNumFrames = frameCount;
simTopCascade_platform                 = platform;


%% calibration cascade parameters
%用于频率校准的范围FFT的插值因子,在校准阶段确定
calibrationInterp              = 5;     %interpolation factor used for range FFT for frequency calibration, determined at calibration stage
calibrationCascade_enable      = 1;
calibrationCascade_binfilePath = [];
calibrationCascade_calibrationfilePath = [];
calibrationCascade_frameIdx = 1;
calibrationCascade_numSamplePerChirp = numSamplePerChirp;
calibrationCascade_nchirp_loops = nchirp_loops;
calibrationCascade_numChirpsPerFrame = numChirpsPerFrame;
calibrationCascade_TxToEnable = TxToEnable;
calibrationCascade_Slope_calib = Slope_calib;
calibrationCascade_Sampling_Rate_sps = adcSampleRate;
calibrationCascade_fs_calib = fs_calib;
calibrationCascade_chirpSlope = chirpSlope;
calibrationCascade_calibrationInterp = calibrationInterp;
calibrationCascade_TI_Cascade_RX_ID = TI_Cascade_RX_ID;
calibrationCascade_RxForMIMOProcess = RxForMIMOProcess;
calibrationCascade_IdTxForMIMOProcess = IdTxForMIMOProcess;
calibrationCascade_numRxToEnable = numRxToEnable;
%1:仅相位校准;0:相位和幅度校准
calibrationCascade_phaseCalibOnly = 1; % 1: only phase calibration; 0: phase and amplitude calibration
%1: adc数据校准开启;0校准关闭
calibrationCascade_adcCalibrationOn = 1; %1: adc data calibration on; 0 calibration off
%1:表示高级帧配置,该值从顶部主文件传递
calibrationCascade_ADVANCED_FRAME_CONFIG = ADVANCED_FRAME_CONFIG; %1 : indicate advance frame config, this value is passed from top main file
calibrationCascade_dataPlatform = dataPlatform;
calibrationCascade_RxOrder = TI_Cascade_RX_ID;
calibrationCascade_NumDevices = NumDevices;

if ADVANCED_FRAME_CONFIG == 1
    %用于在高级帧配置中读取原始adc数据
    calibrationCascade_N_TXForMIMO = N_TXForMIMO; % used for read raw adc data in advanced frame config
    calibrationCascade_NumAnglesToSweep = NumAnglesToSweep;% used for read raw adc data in advanced frame config
end

%% range FFT parameters
rangeProcCascade_enable                = 1;
rangeProcCascade_numAntenna            = numVirtualRxAnt;      % number of antennas
rangeProcCascade_numAdcSamplePerChirp  = numSamplePerChirp;    % number of samples per chirp
rangeProcCascade_rangeFFTSize          = rangeFFTSize;         % FFT size
rangeProcCascade_dcOffsetCompEnable    = 1;
%在范围FFT之前启用或禁用窗口的标志
rangeProcCascade_rangeWindowEnable     = 1;                    % flag to enable or disable windowing before range FFT
% rangeProcCascade_rangeWindowCoeff      = [0.0800, 0.0894, 0.1173, 0.1624, 0.2231, 0.2967, 0.3802, 0.4703, 0.5633...
%                                     0.6553, 0.7426, 0.8216, 0.8890 0.9422, 0.9789, 0.9976]; % range FFT window coefficients
%windowCoeff = hann_local(numSamplePerChirp);
windowCoeff = hanning(numSamplePerChirp);
rangeProcCascade_rangeWindowCoeff      = windowCoeff(1:(numSamplePerChirp/2));
rangeProcCascade_scaleFactorRange      = scaleFactor(log2(rangeFFTSize) - 3);
%1: 应用scaleFactorRange;0:未应用比例因子
rangeProcCascade_FFTOutScaleOn = 0; %1: apply scaleFactorRange; 0: scaling factor not applied

%% Doppler FFT parameters
DopplerProcClutterRemove_enable              = 1;
DopplerProcClutterRemove_numAntenna          = numVirtualRxAnt;      % number of antennas
DopplerProcClutterRemove_numDopplerLines     = rangeFFTSize;         % number of Doppler lines  多普勒线数
DopplerProcClutterRemove_dopplerFFTSize      = DopplerFFTSize;       % Doppler FFT size
DopplerProcClutterRemove_numChirpsPerVirAnt  = numChirpsPerVirAnt;
%多普勒FFT前启用或禁用窗口的标志
DopplerProcClutterRemove_dopplerWindowEnable = 0;                    % flag to enable or disable windowing before Doppler FFT
windowCoeff = hanning(numChirpsPerVirAnt);
DopplerProcClutterRemove_dopplerWindowCoeff = windowCoeff(1:(numChirpsPerVirAnt/2));
DopplerProcClutterRemove_scaleFactorDoppler  = scaleFactor(log2(DopplerFFTSize) - 3);
%1: 应用scaleFactorRange;0:未应用比例因子
DopplerProcClutterRemove_FFTOutScaleOn       = 0; %1: apply scaleFactorRange; 0: scaling factor not applied
%1=启用杂波消除;0=否
DopplerProcClutterRemove_clutterRemove       = 0;                        %1=enable clutter removal; 0=no


%% detection parameters
ind = find(D(:,2)==0);
[val ID_unique] = unique(D(ind,1));
%仅用于唯一方位ID的虚拟通道ID
antenna_azimuthonly = ind(ID_unique); %virtual channel ID only for unique azimuth ID

CFAR_CASO_enable             = 1;
%(CASO-CFAR)双通道rng/dop;仅支持一种恒虚警方法
CFAR_CASO_detectMethod       = 1;                %(CASO-CFAR)dualpass rng/dop; only support one CFAR method
CFAR_CASO_numAntenna         = numVirtualRxAnt; %number of antennas
%估计噪声方差的参考单元数
CFAR_CASO_refWinSize         = [8, 4];          % number of reference cells to estimate noise variance
%防止泄漏被检测为信号的间隙单元数量
CFAR_CASO_guardWinSize       = [8, 0];           % number of gap cells to prevent leakage being detected as signal
%阈值比例因子——6.3对应于8dB的SNR
CFAR_CASO_K0                 = [5 3];       % Threshold scaling factor -- 6.3 corresponds to SNR of 8dB
%1: 仅在窗口内最大时检测;0:否则
CFAR_CASO_maxEnable          = 0;                %1: detect only if it is the maximum within window; 0: otherwise
%用于确定用于检测的噪声级的百分比
CFAR_CASO_ratio_OS           = 0.65;             % percentage used to determine noise level used for detection
CFAR_CASO_rangeBinSize    = rangeBinSize;
CFAR_CASO_velocityBinSize  = velocityBinSize;
CFAR_CASO_dopplerFFTSize     = DopplerFFTSize;   % Doppler FFT size
%如果检测到的信号功率低于该水平,则丢弃该目标。
CFAR_CASO_powerThre          = 0;                % if power of detected signal is less than this level, drop off this object.
%由于DC周围的失真(正频率)而丢弃的范围盒数
CFAR_CASO_discardCellLeft    = 10;                % Number of range bins to discard due to distortions around DC (positive frequencies)
%由于DC周围的失真(负频率)而丢弃的范围箱数量
CFAR_CASO_discardCellRight   = 20;               % Number of range bins to discard due to distortions around DC (negative frequencies)
CFAR_CASO_numRxAnt           = length(RxForMIMOProcess);
CFAR_CASO_TDM_MIMO_numTX     = length(TxForMIMOProcess);
%仅用于唯一方位ID的虚拟通道ID
CFAR_CASO_antenna_azimuthonly = antenna_azimuthonly; %virtual channel ID only for unique azimuth ID
%在该范围内,流量计不应用最大速度扩展
CFAR_CASO_minDisApplyVmaxExtend = 10; % meter, within this range, do not apply max velocity extension
CFAR_CASO_applyVmaxExtend = 0;

%find the overlap antenna ID that can be used for phase compensation
%查找可用于相位补偿的重叠天线ID
TX_ID_MIMO = repmat(1:length(TxForMIMOProcess),length(RxForMIMOProcess),1);
TX_ID_MIMO = TX_ID_MIMO(:);
sumTwo = D(:,1)*10 + D(:,2);
[val id] = unique(sumTwo);
id_repeat = setxor(id, 1:length(sumTwo));

overlapAntenna_ID = [];   % 重叠天线ID
%found the overlap antenna ID
%找到重叠天线ID
for ii = 1:length(id_repeat)
    %ID of pair
    %配对ID
    overlapAntenna_ID(ii,1:2) = find(sumTwo == sumTwo(id_repeat(ii)));
    %associated TX of each pair
    %每对的相关发送
    overlapAntenna_ID(ii,3:4) =TX_ID_MIMO(overlapAntenna_ID(ii,1:2));
end

if length(overlapAntenna_ID) > 0
    %find the pairs offset only by 1 chirp/TX in time
    %在时间上仅查找1个啁啾/TX的对偏移
    dif_TX = abs(overlapAntenna_ID(:,3) - overlapAntenna_ID(:,4));
    ID_dif_1TX = find((dif_TX) == 1 );
    CFAR_CASO_overlapAntenna_ID = overlapAntenna_ID(ID_dif_1TX,:);
    ID_dif_2TX = find(dif_TX == 2);
    CFAR_CASO_overlapAntenna_ID_2TX = overlapAntenna_ID(ID_dif_2TX,:);
    ID_dif_3TX = find(dif_TX == 3);
    CFAR_CASO_overlapAntenna_ID_3TX = overlapAntenna_ID(ID_dif_3TX,:);
else
    CFAR_CASO_overlapAntenna_ID = [];
    CFAR_CASO_overlapAntenna_ID_2TX = [];
    CFAR_CASO_overlapAntenna_ID_3TX = [];
    
end


%% DOA parameters
% optimal d value used of for RF frequency of 76G 77G 78G 79G 80G
%用于76G 77G 78G 79G 80G射频频率的最佳d值
%d_optimal_calib = [0.495 0.504 0.51 0.516 0.522];
% switch centerFreq
%     case 76
%         d_optimal = d_optimal_calib(1);
%     case 77
%         d_optimal = d_optimal_calib(2);
%     case 78
%         d_optimal = d_optimal_calib(3);
%     case 79
%         d_optimal = d_optimal_calib(4);
%     case 80
%         d_optimal = d_optimal_calib(5);
% end

d_optimal = 0.5 * centerFreq / TI_Cascade_Antenna_DesignFreq;

DOACascade_enable                = 1;
DOACascade_D = D;
DOACascade_DOAFFTSize = 256;
DOACascade_numAntenna          = numVirtualRxAnt;
DOACascade_antPos          = [0:numVirtualRxAnt-1];
DOACascade_antDis              = d_optimal;              % in terms of lamda   就lamda而言
%1:2D多目标波束形成,2:2D多目标波束形成和azi/ele FFT后的峰值搜索
DOACascade_method              = 1;                % 1: 2D  muli-object beamforming, 2: 2D  muli-object beamforming and peak search after azi/ele FFT
%在方位角上运行2D DOA的视野
DOACascade_angles_DOA_az=[-80 80]; %field of view to run 2D DOA in azimuth
%在仰角中运行二维DOA的视野
DOACascade_angles_DOA_ele = [-20 20];%field of view to run 2D DOA in elevation
%用于峰值检测
DOACascade_gamma  = 10^(0.2/10);      % Used in peak detection
%用于在方位扫描2D DOA中抑制旁瓣
DOACascade_sidelobeLevel_dB_azim = 1; % used to reject sidelobe in azimuth run 2D DOA
%用于抑制仰角运行2D DOA中的旁瓣
DOACascade_sidelobeLevel_dB_elev = 0;% used to reject sidelobe in elevation run 2D DOA
DOACascade_dopplerFFTSize      = DopplerFFTSize;




simTopCascade.m

%  Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ 
%  
%  
%   Redistribution and use in source and binary forms, with or without 
%   modification, are permitted provided that the following conditions 
%   are met:
%  
%     Redistributions of source code must retain the above copyright 
%     notice, this list of conditions and the following disclaimer.
%  
%     Redistributions in binary form must reproduce the above copyright
%     notice, this list of conditions and the following disclaimer in the 
%     documentation and/or other materials provided with the   
%     distribution.
%  
%     Neither the name of Texas Instruments Incorporated nor the names of
%     its contributors may be used to endorse or promote products derived
%     from this software without specific prior written permission.
%  
%   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
%   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
%   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
%   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
%   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
%   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
%   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
%   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
%   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
%   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
%   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%  
% 

%simTopCascade.m
%
%simTopCascade module definition. Contains some top level parameters. 
%simTopCascade模块定义。包含一些顶级参数。

classdef simTopCascade < Module
    %% properties
    % 属性
    properties (Access = public)
        inputDataSource          = 'bin'; % choose from 'mat','bin','gen'
        outputDataSavingEnable   = 0;
        outputDataFileName       = [];        
        platform = [];
        totNumFrames = 0;
    end
    
    methods
        %% constructor
         %构造函数
        function obj = simTopCascade(varargin)      % varargin = ['pfile'] {'input\test1_param.m'}
            if(isempty(find(strcmp(varargin,'name'), 1)))   % strcmp比较字符串
               varargin = [varargin, 'name','simTopCascade']; % varargin = ['pfile'] {'input\test1_param.m'}  'name','simTopCascade'
            end 
            [email protected](varargin{:});
            
            obj.enable = getParameter(obj, 'enable');    %获取参数
            obj.inputDataSource = getParameter(obj, 'inputDataSource');  
            obj.outputDataSavingEnable = getParameter(obj, 'outputDataSavingEnable');             
            obj.outputDataFileName = getParameter(obj, 'outputDataFileName');             
            obj.platform = getParameter(obj, 'platform');             
            obj.totNumFrames = getParameter(obj, 'totNumFrames');  
          
            
            % overwritten the property value inside parameter file
            %setProperties(obj, nargin, varargin{:});
            obj = set(obj, varargin{:});            

 
        end
        
        
        
        

    end        
end

getParameter.m

function par = getParameter(obj, varargin)


try
    str = fullfile(obj.name, varargin{:});
    str = strrep(str, filesep, '_');

    %eval(obj.pfile);
    run(obj.pfile);
    par = eval(str);
    
catch
    error(['MODULE:' obj.name], 'Invalid parameter');
end

calibrationCascade.m

 

rangeProcCascade.m

 

DopplerProcClutterRemove.m

 

CFAR_CASO.m

 

DOACascade.m

 

getUniqueFileIdx.m



function [binId_unique]= getUniqueFileIdx(dataFolder_test)

currentFolder = pwd;   % pwd确定当前文件夹
cd(dataFolder_test);
listing = dir('*_data.bin');
cd(currentFolder);

% (a) Find all the binaryFile Id numbers
% Search for '_' and extract the numerical value
%(a)查找所有二进制文件Id号
%搜索‘_’并提取数值
binFileId = [];
for jj=1:length(listing)
fileName = listing(jj).name;
[ind]=find(fileName == '_');
binIdnumSearch = str2num(fileName(ind(1)+1:ind(2)-1));
binFileId = [binFileId; binIdnumSearch];
end
binFileId = unique(binFileId);
binId_unique = {};
for jj=1:length(binFileId)
binId_unique{jj} = num2str(binFileId(jj),'%04d');
end


getBinFileNames_withIdx.m

 % 获取Master、Slave1、Slave2、Slave3的文件名    带‘0000’的文件

getValidNumFrames.m

 % Get Valid Number of Frames 获取有效的帧数

% get number of valid frames in the associated *_data.bin file captured
% with TDA2 platform

% File header in *_idx.bin:
%     struct Info
%     {
%         uint32_t tag;
%         uint32_t version;
%         uint32_t flags;
%         uint32_t numIdx;       // number of frames 
%         uint64_t dataFileSize; // total data size written into file
%     };
% 
% Index for every frame from each radar:
%     struct BuffIdx
%     {
%         uint16_t tag;
%         uint16_t version; /*same as Info.version*/
%         uint32_t flags;
%         uint16_t width;
%         uint16_t height;
%         uint32_t pitchOrMetaSize[4]; /*For image data, this is pitch.
%                                                        For raw data, this is size in bytes per metadata plane.*/
%         uint32_t size; /*total size in bytes of the data in the buffer (sum of all planes)*/
%         uint64_t timestamp;
%         uint64_t offset;
%     };


function [numIdx dataFileSize] = getValidNumFrames(adcIdxFileName)

idxFile = fopen(adcIdxFileName,'r');
heaferInfoSize = 6;     
heaferInfo = fread(idxFile, heaferInfoSize,'uint32');
%有效帧数
numIdx = heaferInfo(4); % number of effective frame  
fclose(idxFile);
idxFile = fopen(adcIdxFileName,'r');
heaferInfoSize = 3;
heaferInfo = fread(idxFile, heaferInfoSize,'uint64');
%有效帧数的数据大小
dataFileSize = heaferInfo(3); % data size for the effective number of frames
fclose(idxFile);

end

 

 

 

 

 

 

datapath.m

%数据路径.m
%
%calibrationCascade模块的datapath功能,该功能使用安装有calibrationfilePath给定路径名的校准矩阵校准ADC数据。在进一步处理之前,直接对原始ADC数据进行校准。在时域中应用频率和相位校准;振幅校准是可选的,可以打开或关闭
%输入
%obj:calibrationCascade的对象实例

%datapath.m
%
% datapath function of calibrationCascade module, this function calibrates the ADC data with the calibration
% matrix installed with the path name given by calibrationfilePath.
% Calibration is done directly on the raw ADC data before any further
% processing. Apply frequency and phase calibration in time domain; amplitude
% calibration is optional, can be turned on or off
%
%input
%   obj: object instance of calibrationCascade


function outData = datapath(obj)

%load calibration file
load(obj.calibrationfilePath);
RangeMat = calibResult.RangeMat;
PeakValMat = calibResult.PeakValMat;

fileFolder = obj.binfilePath;
frameIdx = obj.frameIdx;

numSamplePerChirp = obj.numSamplePerChirp;
nchirp_loops = obj.nchirp_loops;
numChirpsPerFrame = obj.numChirpsPerFrame;
TxToEnable = obj.TxToEnable;
Slope_calib = obj.Slope_calib;
fs_calib = obj.fs_calib;
Sampling_Rate_sps = obj.Sampling_Rate_sps;

chirpSlope = obj.chirpSlope;
calibrationInterp = obj.calibrationInterp;
TI_Cascade_RX_ID = obj.TI_Cascade_RX_ID;
RxForMIMOProcess = obj.RxForMIMOProcess;
IdTxForMIMOProcess = obj.IdTxForMIMOProcess;
numRX = obj.numRxToEnable;
phaseCalibOnly = obj.phaseCalibOnly;
adcCalibrationOn = obj.adcCalibrationOn;
N_TXForMIMO = obj.N_TXForMIMO;
NumAnglesToSweep =  obj.NumAnglesToSweep ;
RxOrder = obj.RxOrder;
NumDevices = obj.NumDevices;

numTX = length(TxToEnable);
outData = [];


fileName=[fileFolder];
switch obj.dataPlatform

    case 'TDA2'
        numChirpPerLoop = obj.numChirpsPerFrame/obj.nchirp_loops; 
        numLoops = obj.nchirp_loops;  
        %固定数量
        numRXPerDevice = 4; % Fixed number    每个设备的接收数  
        [radar_data_Rxchain] = read_ADC_bin_TDA2_separateFiles(fileName,frameIdx,numSamplePerChirp,numChirpPerLoop,numLoops, numRXPerDevice, 1);
    otherwise
        error('Not supported data capture platform!');       
end


%use the first TX as reference by default
TX_ref = TxToEnable(1);

if adcCalibrationOn == 0
    outData = radar_data_Rxchain;
else
    
    for iTX = 1: numTX
        
        %use first enabled TX1/RX1 as reference for calibration
        %使用第一个启用的TX1/RX1作为校准参考
        TXind = TxToEnable(iTX);
%         TXind = iTX;
        %construct the frequency compensation matrix        
        %构建频率补偿矩阵
        freq_calib = (RangeMat(TXind,:)-RangeMat(TX_ref,1))*fs_calib/Sampling_Rate_sps *chirpSlope/Slope_calib;       
        freq_calib = 2*pi*(freq_calib)/(numSamplePerChirp * calibrationInterp);
        correction_vec = (exp(1i*((0:numSamplePerChirp-1)'*freq_calib))');
        
        
        freq_correction_mat = repmat(correction_vec, 1, 1, nchirp_loops);
        freq_correction_mat = permute(freq_correction_mat, [2 3 1]);
        outData1TX = radar_data_Rxchain(:,:,:,iTX).*freq_correction_mat;
        
        
        %construct the phase compensation matrix
        %构造相位补偿矩阵
        phase_calib = PeakValMat(TX_ref,1)./PeakValMat(TXind,:);
        %remove amplitude calibration
        %删除振幅校准
        if phaseCalibOnly == 1
            phase_calib = phase_calib./abs(phase_calib);
        end
        phase_correction_mat = repmat(phase_calib.', 1,numSamplePerChirp, nchirp_loops);
        phase_correction_mat = permute(phase_correction_mat, [2 3 1]);
        outData(:,:,:,iTX) = outData1TX.*phase_correction_mat;
        
    end
end

%re-order the RX channels so that it correspond to the channels of
% ********   16_lamda     ****   4_lamda    ****
% and only maintain RX/TX data used for requred MIMO analysis.
% outData = outData(:,:,RxForMIMOProcess,IdTxForMIMOProcess);
% outData = outData(:,:,RxForMIMOProcess,:);

'E:\MMWAVE STUDIO\mmwave_studio_03_00_00_14\mmWaveStudio\MatlabExamples\4chip_cascade_MIMO_example\main\cascade\input\calibrateResults_high.mat'

read_ADC_bin_TDA2_separateFiles

%% read raw adc data with MIMO 
%%使用MIMO读取原始adc数据
function [radar_data_Rxchain] = read_ADC_bin_TDA2_separateFiles(fileNameCascade,frameIdx,numSamplePerChirp,numChirpPerLoop,numLoops, numRXPerDevice, numDevices)


  dataFolder =fileNameCascade.dataFolderName;
  fileFullPath_master = fullfile(dataFolder,fileNameCascade.master);
  fileFullPath_slave1 = fullfile(dataFolder,fileNameCascade.slave1);
  fileFullPath_slave2 = fullfile(dataFolder,fileNameCascade.slave2);
  fileFullPath_slave3 = fullfile(dataFolder,fileNameCascade.slave3);

 [radar_data_Rxchain_master] = readBinFile(fileFullPath_master, frameIdx,numSamplePerChirp,numChirpPerLoop,numLoops, numRXPerDevice, numDevices);
 [radar_data_Rxchain_slave1] = readBinFile(fileFullPath_slave1, frameIdx,numSamplePerChirp,numChirpPerLoop,numLoops, numRXPerDevice, numDevices);
 [radar_data_Rxchain_slave2] = readBinFile(fileFullPath_slave2, frameIdx,numSamplePerChirp,numChirpPerLoop,numLoops, numRXPerDevice, numDevices);
 [radar_data_Rxchain_slave3] = readBinFile(fileFullPath_slave3, frameIdx,numSamplePerChirp,numChirpPerLoop,numLoops, numRXPerDevice, numDevices);

% Arranged based on Master RxChannels, Slave1 RxChannels, slave2 RxChannels, slave3 RxChannels 
% The RX channels are re-ordered according to "TI_Cascade_RX_ID" defined in
% "module_params.m"
%基于主RX通道、从1 RX通道、从2 RX通道、从3 RX通道排列
%根据中定义的“TI\u Cascade\u RX\u ID”对RX信道进行重新排序
%“模块参数m”
 radar_data_Rxchain(:,:,1:4,:) = radar_data_Rxchain_master;
 radar_data_Rxchain(:,:,5:8,:) = radar_data_Rxchain_slave1;
 radar_data_Rxchain(:,:,9:12,:) = radar_data_Rxchain_slave2;
 radar_data_Rxchain(:,:,13:16,:) = radar_data_Rxchain_slave3;
        
end


function [adcData1Complex] = readBinFile(fileFullPath, frameIdx,numSamplePerChirp,numChirpPerLoop,numLoops, numRXPerDevice, numDevices)
% 每帧预期的采样数
Expected_Num_SamplesPerFrame = numSamplePerChirp*numChirpPerLoop*numLoops*numRXPerDevice*2; 
fp = fopen(fileFullPath, 'r');
fseek(fp,(frameIdx-1)*Expected_Num_SamplesPerFrame*2, 'bof'); % fseek()移至文件中的指定位置
adcData1 = fread(fp,Expected_Num_SamplesPerFrame,'uint16');
neg             = logical(bitget(adcData1, 16));
adcData1(neg)    = adcData1(neg) - 2^16;
%% 
adcData1 = adcData1(1:2:end) + sqrt(-1)*adcData1(2:2:end);   % 实部加虚部  
adcData1Complex = reshape(adcData1, numRXPerDevice, numSamplePerChirp, numChirpPerLoop, numLoops);
adcData1Complex = permute(adcData1Complex, [2 4 1 3]);  % 置换数组维度
fclose(fp);
end

 

 

 

 

 datapath function == rangeFFTOut

        %% datapath function
        % input: adc data, assuming size(input) = [numSamplePerChirp, numChirpsPerFrame numAntenna]
        function [out] = datapath(obj, input)
            
            numLines  = size(input,2);
            numAnt    = size(input,3);
            % dopplerWinLen  = length(obj.dopplerWindowCoeff);
            
            if obj.enable           
                
                % initialize
                out = zeros(obj.rangeFFTSize, numLines, numAnt);
                
                for i_an = 1:numAnt  
                   
                    % vectorized version  %矢量化版本
                    inputMat    = squeeze(input(:,:,i_an));   % squeeze删除长度为 1 的维度
                    
                    % DC offset compensation  直流偏移补偿
                    inputMat    = bsxfun(@minus, inputMat, mean(inputMat));   % 对两个数组应用按元素运算(启用隐式扩展)
                    
                    % apply range-domain windowing  应用范围域窗口
                    inputMat    = bsxfun(@times, inputMat, obj.rangeWindowCoeffVec);
                    
                    % Range FFT
                    fftOutput   = fft(inputMat, obj.rangeFFTSize);
                    
                    % apply Doppler windowing and scaling to the output. Doppler windowing moved to DopplerProc.m (5/24)
                    % fftOutput   = bsxfun(@times, fftOutput, obj.scaleFactorRange*obj.dopplerWindowCoeffVec.');
                    % 对输出应用多普勒窗口和缩放。多普勒窗口移到DopplerProc.m(5/24)
                    if  obj.FFTOutScaleOn == 1      % FFT输出比例开启
                        fftOutput   = fftOutput * obj.scaleFactorRange;
                    end
                    
                    % populate in the data cube
                    %在数据立方体中填充
                    out(:,:,i_an) = fftOutput;
                    
                end            
                
            else
                out     = input;
                
            end
            
        end

datapath function == DopplerFFTObj

        % datapath function
        % input: adc data, assuming size(input) = [numSamplePerChipr numChirpsPerFrame numAntenna]
        function [out] = datapath(obj, input)
            
            numLines  = size(input,1);
            numAnt    = size(input,3);
            
            if obj.enable                  
                
                % initialize
                out = zeros(numLines, obj.dopplerFFTSize, numAnt);
                
                for i_an = 1:numAnt                  
                   
                    %% vectorized version
                    inputMat    = squeeze(input(:,:,i_an));
                    inputMat    = bsxfun(@times, inputMat, obj.dopplerWindowCoeffVec.');
                    if obj.clutterRemove ==1   % 杂波消除
                        inputMat = inputMat - (repmat(mean(inputMat'),size(inputMat,2),1))';
                    end
                    fftOutput   = fft(inputMat, obj.dopplerFFTSize, 2);                         
                    
                    if obj.FFTOutScaleOn ==1  %FFT输出比例开启
                        fftOutput   = fftshift(fftOutput, 2) * obj.scaleFactorDoppler;
                    else
                        fftOutput   = fftshift(fftOutput, 2);
                    end
                    % populate in the data cube
                    %在数据立方体中填充
                    out(:,:,i_an) = fftOutput;
                    
                end
                
            else
                out     = input;
                
            end
            
        end

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_42046837/article/details/125960239

智能推荐

四年级计算机wps教案,四年级上册信息技术教案-《初识“WPS文字”》苏教版新版..._htrbs的博客-程序员秘密

四年级上册信息技术教案-《初识“WPS文字”》苏教版新版==================资料简介======================初识“WPS文字”【教材分析】本课是四年级上学期的第1课时,是“WPS文字”模块的起始课。本节课主要是从启动、认识窗口的组成、保存与退出四个方面让学生开启这一软件的学习。作为学生接触的第二个文字处理软件,学生将利用这一软件在接下来的学习中进一步体会利用信息...

四年级打字计算机上册教案,四年级上册信息技术优秀教案设计_带你进黄铜的博客-程序员秘密

【导语】信息技术的研究包括科学,技术,工程以及管理等学科,这些学科在信息的管理,传递和处理中的应用,相关的软件和设备及其相互作用。无忧考网准备了以下教案,希望对你有帮助!我给文件建新家  一、教材分析本课是这一单元中内容最少的一课,在单元内部起到承上启下的作用,为下一课的文件移动做好准备。二、课前准备1、资料准备将本课的教学素材发放到学生电脑的D盘中。2、教学环境多媒体机房。3、对学生的要求掌握打...

小学四年级计算机课本知识,小学四年级计算机教学计划_你不学固体物理吗的博客-程序员秘密

小学四年级计算机教学计划小学四年级计算机教学计划例1一、本学期教学的主要任务和目的要求1、了解信息技术的应用环境和信息的一些表现形式。2、建立对计算机的感性认识,了解信息技术在日常生活中的应用,培养学生学习、使用计算机的兴趣和意识。3、在使用信息技术时学会与他人合作,学会使用与年龄发展相符的多媒体资源进行学习。4、能够在他人帮助下使用通讯远距离获取信息、与他人沟通,开展直接和独立的学习,发展个人的...

python查看类的属性和方法_Python如何查看对象有哪些内容和属性_二院大蛙的博客-程序员秘密

Python如何查看对象有哪些内容和属性1、查看python对象的内容方法:如下代码:a = [1,2,3]print(type(a))print(a)执行结果是:[1, 2, 3]也就是说通过print(type(对象名))可以输出对象类型,print(对象名)可以输出对象的详细信息。2、查看一个对象有哪些属性使用dir命令,如text="string"dir(text)执行结果是:['__ad...

使用操作系统认识计算机教案,《认识计算机操作系统》教案设计.doc_FasterThanMind的博客-程序员秘密

PAGE 2“三栏式”教学设计科 目信息技术年 级初一设计教师刘志勇设计主题计算机操作系统设计时间2019年9月12日课标要求教材分析本节课主要是让学生了解我们常用操作系统的操作及功能。学情分析本节课学习的对象是初中一年级的学生,具有较高的学习兴趣。本节课是理论与实际操作课,知识内容生动形象,学生热爱学习。经过对WindowsXP的课程学习,具有一定的操作与动手能力。教学目标1.使学生能够...

清华大学自动化系和计算机系,黄高 -清华大学自动化系_铜板响叮当的博客-程序员秘密

主要会议论文1. Yulin Wang, Zanlin Ni, Shiji Song, Le Yang, Gao Huang. Revisiting Locally Supervised Learning: an Alternative to End-to-end Training, International Conference on Learning Representations (I...

随便推点

python跳舞的线_这是什么舞啊?详细介绍加50分!!_weixin_39628256的博客-程序员秘密

展开全部Boogaloo Sam : popping风格和Boogaloo风格的创始人 SLIDE(NATE)EB诞生于1977年Boogaloo Sam创建The Electric Boogaloo Lockers的时候 - 原始团队为: THE ELECTRIC BOOGALOO LOCKERS (1977,Fresno城,加利福尼亚州e69da5e887aa62616964757a68696...

DPDK Sample Applications User Guides(11)IP Fragmentation样例应用程序_chaoshuaihaohao的博客-程序员秘密

官方文档查看地址:http://doc.dpdk.org/guides/sample_app_ug/ip_frag.htmlPDF下载地址:https://www.intel.com/content/www/us/en/embedded/technology/packet-processing/dpdk/dpdk-sample-applications-user-guide.html本篇难...

linux opengl 错误,ubuntu linux上的opengl - 链接器错误:未定义引用[重复]_五伤先生的博客-程序员秘密

这个问题在这里已有答案:我只想从openGL编程开始,所以我从ubuntu的存储库安装了freeglut3,我安装了所有的mesa软件包,以及build-essentials .后来,我复制了一个简单的例子openGL wiki首先,我尝试用以下方法编译它: gcc triangle.c -o triangle.o ;但是,稍后,我在这里阅读:Linker error : undefined re...

fragment 淡入淡出_Fragment之Fragmentation库(添加转场动画)_weixin_42255060的博客-程序员秘密

部分内容来源于别人的总结,如有冒犯侵权,请告知! 邮箱:[email protected]谢谢!我只想做一个记录,以免自己以后出现不知道怎么解决.Fragmentation库:非常适合单Activity+多Fragment 或者 多模块Activity+多Fragment的架构特性1、快速开发出各种嵌套设计的Fragment App2、实时查看Fragment的(包括嵌套Fragment)栈视图...

JAVA SPI机制_曉~~的博客-程序员秘密_hibernate中的spi机制

spi是java提供的一套用来加载第三方实现或扩展的服务发现机制,利用spi可以根据实际需求,轻松的启用、扩展、或者替换对应接口的实现策略。什么是spi? spi全称Service Provider Interface, 是java提供的一套用来加载第三方实现或扩展的服务发现机制,利用spi可以根据实际需求,轻松的启用、扩展、或者替换对应接口的实现策略,在许多知名框架中都利用了该项机制,将服务接口与服务实现分离以达到解耦,提高程序可扩展性。spi接口的约定...

linux常见命令_kunzai6的博客-程序员秘密

在linux中运行命令行时,可以通过将命名行统一写在一个shell文件夹中运行,更加方便。步骤:1.新建start.sh后缀的文件,2.将start.sh文件复制到linux相应文件夹下3.给.sh文件设置操作权限: chmod 777 start.sh4.如果是在windows下新建的文件,需要注意重新编码,这里采用dos2unix方式: y...

推荐文章

热门文章

相关标签