-
Notifications
You must be signed in to change notification settings - Fork 3
/
calibAdcData.m
52 lines (43 loc) · 2.65 KB
/
calibAdcData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function adcData = calibAdcData(rawAdcData, calibFileName, parameter_files_path)
adcData = struct();
calibData = load(calibFileName);
NumSubFramesPerFrame = length(rawAdcData);
for i_subFrame = 0 : NumSubFramesPerFrame - 1
adcData(i_subFrame+1).subframeIdx = rawAdcData(i_subFrame+1).subframeIdx;
radar_data_Rxchain = rawAdcData(i_subFrame+1).rawAdcData;
curTransferOrder = getPara(parameter_files_path(i_subFrame+1).path, 'curTransferOrder');
numTX = length(curTransferOrder);
Sampling_Rate_sps = getPara(parameter_files_path(i_subFrame+1).path, 'adcSampleRate');
chirpSlope = getPara(parameter_files_path(i_subFrame+1).path, 'chirpSlope');
numSamplePerChirp = getPara(parameter_files_path(i_subFrame+1).path, 'numADCSample');
nchirp_loops = getPara(parameter_files_path(i_subFrame+1).path, 'NumChirpLoops');
RangeMat = calibData.calibResult.RangeMat;
fs_calib = calibData.params.Sampling_Rate_sps;
Slope_calib = calibData.params.Slope_MHzperus * 1e12;
calibrationInterp = getPara(parameter_files_path(i_subFrame+1).path, 'calibrationInterp');
PeakValMat = calibData.calibResult.PeakValMat;
phaseCalibOnly = getPara(parameter_files_path(i_subFrame+1).path, 'calibrationCascade_phaseCalibOnly');
clear outData;
TX_ref = curTransferOrder(1);
for iTX = 1: numTX
TXind = curTransferOrder(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
adcData(i_subFrame+1).adcData = outData;
end
end