Initial ARSS. Need to improve and add functions.

This commit is contained in:
2026-03-02 14:48:21 +09:00
commit 775668afdb
20 changed files with 1610 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
function quantized_data = apply_adc_quantization(adc_raw_data, n_bits, v_full_scale, mode)
% :
% - adc_raw_data: HPF/LPF가 (Voltage Scale)
% - n_bits: ADC
% - v_full_scale: ADC Peak-to-Peak (e.g., 2.0V)
% - mode: 'IQ' (Complex ) 'Real' (Real )
v_max = v_full_scale / 2;
lsb = v_full_scale / (2^n_bits);
if strcmpi(mode, 'IQ')
% --- Case 1: I/Q Demodulation (Complex) ---
% I채널과 Q채널 Clipping Quantization
r_part = real(adc_raw_data);
i_part = imag(adc_raw_data);
r_part = max(min(r_part, v_max), -v_max);
i_part = max(min(i_part, v_max), -v_max);
q_r = round(r_part / lsb) * lsb;
q_i = round(i_part / lsb) * lsb;
quantized_data = q_r + 1j * q_i;
elseif strcmpi(mode, 'Real')
% --- Case 2: Real Demodulation ---
% (I채널) ADC
%
r_part = real(adc_raw_data);
r_part = max(min(r_part, v_max), -v_max);
q_r = round(r_part / lsb) * lsb;
% (Real)
quantized_data = q_r;
else
error(' IQ Real .');
end
end
+39
View File
@@ -0,0 +1,39 @@
function filtered_data = apply_analog_hpf(adc_raw_data, fs_adc, fc_hpf_Hz)
% :
% - adc_raw_data: [NumRx, NumTx, NumChirps, N_samples]
% - fs_adc: ADC (Hz)
% - fc_hpf_Hz: HPF (Cut-off Frequency, Hz)
[NumRx, NumTx, NumChirps, N_samples] = size(adc_raw_data);
filtered_data = zeros(size(adc_raw_data));
% 1. 1 HPF (S-plane -> Z-plane )
% Analog Transfer Function: H(s) = s / (s + omega_c)
omega_c = 2 * pi * fc_hpf_Hz;
% (Bilinear Transform)
% [b, a] = butter(1, fc_hpf_Hz / (fs_adc/2), 'high'); %
T = 1 / fs_adc;
alpha = 2 / T;
b0 = alpha / (alpha + omega_c);
b1 = -alpha / (alpha + omega_c);
a1 = (omega_c - alpha) / (alpha + omega_c);
b = [b0, b1];
a = [1, a1];
% 2.
for rx = 1:NumRx
for tx = 1:NumTx
for m = 1:NumChirps
% 퀀
raw_sig = squeeze(adc_raw_data(rx, tx, m, :));
% ( 'filtfilt' 'filter' )
% (Causal) filter
filtered_data(rx, tx, m, :) = filter(b, a, raw_sig);
end
end
end
end
+203
View File
@@ -0,0 +1,203 @@
function [adc_raw_data, adc_combined] = apply_lna_and_mixer(RxOut, TxOut, RadarParams)
% : adc_raw_data [NumRx, NumTx, NumChirps, N_adc_samples] -
% adc_combined [NumRx, NumChirps, N_adc_samples] - ADC ( TX )
% : RxOut, TxOut, RadarParams
% MIMO TX .
Timing = RadarParams.Waveform.Timing;
fs_adc = RadarParams.Waveform.fs_adc;
f_start = RadarParams.Waveform.f_start;
Slope = RadarParams.Waveform.Slope;
pn_level = RadarParams.Waveform.nonideal.pn_level;
f_ripple = RadarParams.Waveform.nonideal.f_ripple;
peak_phase_error = RadarParams.Waveform.nonideal.peak_phase_error;
enable_phase_noise = true;
enable_nonlinearity = true;
if isfield(RadarParams.Waveform.nonideal, 'enable_phase_noise')
enable_phase_noise = logical(RadarParams.Waveform.nonideal.enable_phase_noise);
end
if isfield(RadarParams.Waveform.nonideal, 'enable_nonlinearity')
enable_nonlinearity = logical(RadarParams.Waveform.nonideal.enable_nonlinearity);
end
use_datasheet_phase_noise = false;
phase_noise_cfg = struct();
if isfield(RadarParams.Waveform.nonideal, 'phaseNoise')
phase_noise_cfg = RadarParams.Waveform.nonideal.phaseNoise;
if isfield(phase_noise_cfg,'enabled') && phase_noise_cfg.enabled && ...
isfield(phase_noise_cfg,'offset_Hz') && isfield(phase_noise_cfg,'level_dBc_Hz')
use_datasheet_phase_noise = true;
end
end
mimoMode = RadarParams.Waveform.mimoMode;
NumTx = RadarParams.Antenna.NumTx;
rxPathGain_dB = RadarParams.Rxpath.rxPathGain_dB;
system_NF_dB = RadarParams.Rxpath.system_NF_dB;
PA_Profile = RadarParams.RFOutput.PA_Profile;
SpurParams = RadarParams.SpurParams;
enable_spur = true;
if isstruct(SpurParams) && isfield(SpurParams, 'enabled')
enable_spur = logical(SpurParams.enabled);
end
[NumTargets, NumRx, ~, NumChirps, N_adc_samples] = size(RxOut.space_loss_amp);
% TDM : TX별
if strcmpi(mimoMode, 'TDM') && mod(NumChirps, NumTx) ~= 0
error('TDM mode requires NumChirps to be a multiple of NumTx. Current NumChirps=%d, NumTx=%d.', NumChirps, NumTx);
end
% t=0 ( ) , ADC
t_adc = Timing.AdcStartTime : 1/fs_adc : (Timing.AdcStartTime + Timing.AdcSampTime - 1/fs_adc);
f_inst = f_start + Slope * t_adc;
% --- 1. PA_Profile을 (Vtx) ---
% PA_Profile의 ( PA_Profile(:,1), PA_Profile(:,2) )
if isstruct(PA_Profile)
P_inst_dBm = interp1(PA_Profile.freqs, PA_Profile.power_dBm, f_inst, 'linear', 'extrap');
else
P_inst_dBm = interp1(PA_Profile(:,1), PA_Profile(:,2), f_inst, 'linear', 'extrap');
end
% dBm -> Watt -> (V) (50 )
Vtx_inst = sqrt(10.^((P_inst_dBm - 30) / 10) * 50);
% --- 2. ---
T_ref = RadarParams.Basic.T0;
P_noise_floor_W = RadarParams.Basic.kb * T_ref * fs_adc;
rxPathGain_lin = 10^(rxPathGain_dB/10);
system_NF_lin = 10^(system_NF_dB/10);
% ADC
P_noise_total_W = P_noise_floor_W * system_NF_lin * rxPathGain_lin;
sigma_n = sqrt(P_noise_total_W * 50);
% --- MIMO TX ---
% TDM: TX만
% DDMA: TX +
% legacy phase-noise model ( )
window_size = 50;
ma_filter = ones(1,window_size)/window_size;
% --- 3. ADC Raw Data ---
adc_raw_data = zeros(NumRx, NumTx, NumChirps, N_adc_samples);
for m = 1:NumChirps
% generate phase noise & nonlinearity for this chirp
t_rel = t_adc; % time within chirp
if enable_phase_noise && use_datasheet_phase_noise
phi_noise = generate_phase_noise_from_datasheet(t_rel, phase_noise_cfg);
elseif enable_phase_noise
phi_noise = pn_level * filter(ma_filter, 1, randn(1, N_adc_samples));
else
phi_noise = zeros(1, N_adc_samples);
end
phi_nonlin = zeros(1, N_adc_samples);
if enable_nonlinearity
ramp_idx2 = (t_rel >= Timing.IdleTime);
phi_nonlin(ramp_idx2) = peak_phase_error * sin(2 * pi * f_ripple * (t_rel(ramp_idx2) - Timing.IdleTime));
end
% MIMO TX
if strcmpi(mimoMode, 'TDM')
% TDM: TX (1,2,3,1,2,3,...)
active_tx_list = mod(m - 1, NumTx) + 1; % : m=1TX1, m=2TX2, m=3TX1...
elseif strcmpi(mimoMode, 'DDMA')
% DDMA: TX
active_tx_list = 1:NumTx;
else
% : TX
active_tx_list = 1:NumTx;
end
for tx = 1:NumTx
% TDM TX는
if strcmpi(mimoMode, 'TDM') && ~ismember(tx, active_tx_list)
adc_raw_data(:, tx, m, :) = 0; % TX는 0
continue;
end
for rx = 1:NumRx
signal_mix = zeros(1, N_adc_samples);
for kt = 1:NumTargets
% (1) : Vtx(f) * G_tx * Space_Loss(f) * G_rx * rxPathGain
A_path = squeeze(RxOut.space_loss_amp(kt, rx, tx, m, :))';
% (Vtx_inst)
A_total = Vtx_inst .* (TxOut.G_tx_amp(kt, tx) * A_path * sqrt(rxPathGain_lin));
% (2) TTD Beat Phase ( t_adc )
tau = squeeze(RxOut.tau(kt, rx, tx, m, :))';
beat_phase = 2*pi * (f_start * tau + Slope * tau .* t_adc - 0.5 * Slope * tau.^2);
% add transmit impairments (phase noise + nonlinearity)
beat_phase = beat_phase + phi_noise + phi_nonlin;
% (3) DDMA
if strcmpi(mimoMode, 'DDMA')
phase_shift = 2 * pi * (tx - 1) * (m - 1) / NumTx;
beat_phase = beat_phase + phase_shift;
end
% (4)
base_sig = A_total .* exp(1j * beat_phase);
if enable_spur && exist('SpurParams','var') && ~isempty(SpurParams)
spur_vec = generate_spur(SpurParams, t_adc, base_sig);
signal_mix = signal_mix + base_sig + spur_vec;
else
signal_mix = signal_mix + base_sig;
end
end
% (5)
noise = (sigma_n/sqrt(2)) * (randn(1, N_adc_samples) + 1j*randn(1, N_adc_samples));
adc_raw_data(rx, tx, m, :) = signal_mix + noise;
end
end
end
% --- 4. ADC ( TX RX별로 ) ---
% RX가 TX
adc_combined = zeros(NumRx, NumChirps, N_adc_samples);
for m = 1:NumChirps
for rx = 1:NumRx
% TX의
combined_signal = squeeze(sum(adc_raw_data(rx, :, m, :), 2));
% ADC spur이 (orientation )
if enable_spur && exist('SpurParams','var') && isfield(SpurParams,'adc')
spur_adc = generate_spur(SpurParams, t_adc);
% ensure same shape as combined_signal (Nx1 vs 1xN)
spur_adc = reshape(spur_adc, size(combined_signal));
combined_signal = combined_signal + spur_adc;
end
adc_combined(rx, m, :) = combined_signal;
end
end
% --- 5. : DC offset/LO leakage clipping ---
if enable_spur && exist('SpurParams','var')
% LO leakage: /DC
if isfield(SpurParams,'lo_leak')
dc_amp = SpurParams.lo_leak.amp;
adc_combined = adc_combined + dc_amp;
end
% Clipping spur:
if isfield(SpurParams,'clip')
target_range = SpurParams.clip.range;
beat_freq = 2 * Slope * target_range / RadarParams.Basic.c;
clip_amp = SpurParams.clip.amp;
for m = 1:NumChirps
% ()
clip_tone = clip_amp * cos(2*pi*beat_freq*t_adc);
for rx = 1:NumRx
adc_combined(rx, m, :) = adc_combined(rx, m, :) + reshape(clip_tone, [1, 1, length(clip_tone)]);
end
end
end
end
end
@@ -0,0 +1,58 @@
function phi_noise = generate_phase_noise_from_datasheet(t, phaseNoiseCfg)
% DATASHEET SSB phase noise(dBc/Hz) (rad)
% :
% t : [1xN] [Nx1] ()
% phaseNoiseCfg.offset_Hz : (Hz)
% phaseNoiseCfg.level_dBc_Hz : SSB phase noise (dBc/Hz)
% :
% phi_noise : [1xN] (rad)
t = t(:);
N = numel(t);
phi_noise = zeros(1, N);
if N < 2
return;
end
dt = mean(diff(t));
fs = 1 / dt;
df = fs / N;
offsets = phaseNoiseCfg.offset_Hz(:);
levels_dBc = phaseNoiseCfg.level_dBc_Hz(:);
valid = isfinite(offsets) & isfinite(levels_dBc) & offsets > 0;
offsets = offsets(valid);
levels_dBc = levels_dBc(valid);
if isempty(offsets)
return;
end
[offsets, order] = sort(offsets, 'ascend');
levels_dBc = levels_dBc(order);
f_pos = (1:floor(N/2))' * df;
if isempty(f_pos)
return;
end
if numel(offsets) == 1
L_dBc = levels_dBc(1) * ones(size(f_pos));
else
L_dBc = interp1(log10(offsets), levels_dBc, log10(f_pos), 'linear', 'extrap');
end
% SSB phase noise L(f) PSD : L(f) ~= 0.5 * S_phi(f)
% => S_phi(f) ~= 2 * 10^(L(f)/10) [rad^2/Hz]
S_phi = 2 * 10.^(L_dBc / 10);
%
amp = sqrt(2 * S_phi * df); % (rad)
rand_phase = 2 * pi * rand(size(f_pos));
t_rel = t - t(1);
% NxK
phase_matrix = 2*pi*(t_rel * f_pos.') + rand_phase.';
phi_noise = (cos(phase_matrix) * amp).';
phi_noise = phi_noise(:).';
end
+83
View File
@@ -0,0 +1,83 @@
function spur = generate_spur(SpurParams, t, baseSignal)
%GENERATE_SPUR create spur signals based on a parameter structure
% spur = GENERATE_SPUR(SpurParams, t, baseSignal)
% t : time vector (row or column)
% baseSignal : (optional) complex baseband signal used for some spur
% mechanisms such as mixer nonlinearity. If omitted the
% function will only generate independent tones.
%
% SpurParams is a struct that may contain any of the following fields
% .lo : struct with fields amp, freq, phase (optional) -
% LO-related spur added to phase of signal
% .mixer : struct with fields alpha2, alpha3 - coefficients for
% 2nd/3rd order nonlinearity. Requires baseSignal input.
% .adc : struct with fields amp, freq, phase - tone added after
% ADC (complex). Does not require baseSignal.
% .switch : struct with fields amp, freq - square/pulse spur
% .pulse : struct with fields amp, freq, duty (01), phase -
% periodic gating/pulse train (lock) added to output
%
% Example:
% SpurParams = struct();
% SpurParams.lo = struct('amp',0.01,'freq',1e6,'phase',0);
% SpurParams.mixer= struct('alpha2',1e-4,'alpha3',1e-6);
% SpurParams.adc = struct('amp',1e-3,'freq',2e6,'phase',0);
% SpurParams.switch = struct('amp',5e-4,'freq',5e5);
% SpurParams.pulse = struct('amp',0.02,'freq',500e3,'duty',0.1,'phase',0);
% LO , , ADC ,
% 10% duty pulse train .
%
% The returned spur vector has the same dimensions as t. If baseSignal
% is supplied the mixer nonlinearity is computed elementwise using that
% signal; otherwise only independent spur terms are returned.
if nargin < 3
baseSignal = [];
end
% ensure t is row for consistent operations
t = t(:)';
spur = zeros(size(t));
if isfield(SpurParams, 'lo')
p = SpurParams.lo;
phase = 0;
if isfield(p, 'phase'); phase = p.phase; end
spur = spur + p.amp .* sin(2*pi*p.freq .* t + phase);
end
if isfield(SpurParams, 'mixer') && ~isempty(baseSignal)
m = SpurParams.mixer;
% apply polynomial nonlinearity to the provided base signal
if isfield(m, 'alpha2')
spur = spur + m.alpha2 .* (baseSignal.^2);
end
if isfield(m, 'alpha3')
spur = spur + m.alpha3 .* (baseSignal.^3);
end
end
if isfield(SpurParams, 'adc')
a = SpurParams.adc;
phase = 0;
if isfield(a, 'phase'); phase = a.phase; end
spur = spur + a.amp .* exp(1j*(2*pi*a.freq .* t + phase));
end
if isfield(SpurParams, 'switch')
s = SpurParams.switch;
spur = spur + s.amp .* square(2*pi*s.freq .* t);
end
if isfield(SpurParams, 'pulse')
p = SpurParams.pulse;
% duty default 50%
duty = 0.5;
if isfield(p,'duty'); duty = p.duty; end
phase = 0;
if isfield(p,'phase'); phase = p.phase; end
% generate pulse train (0/1) scaled by amp
% square with duty cycle multiplied then shifted to [0,1]
pulse_wave = (square(2*pi*p.freq .* t + phase, duty*100)+1)/2;
spur = spur + p.amp .* pulse_wave;
end
end
+21
View File
@@ -0,0 +1,21 @@
function RxOut = receive_antenna(ChannelOut, Target, RxPattern)
[NumTargets, NumRx, NumTx, NumChirps, N_adc] = size(ChannelOut.space_loss_amp);
RxOut = ChannelOut;
for k = 1:NumTargets
for rx = 1:NumRx
pat = RxPattern(rx);
if strcmpi(pat.Type, '2D')
g_dBi = interp2(pat.az_angles, pat.el_angles, pat.gain_dBi, Target.az(k), Target.el(k), 'linear', -20);
else
g_az = interp1(pat.az_angles, pat.gain_az_dBi, Target.az(k), 'linear', -20);
g_el = interp1(pat.el_angles, pat.gain_el_dBi, Target.el(k), 'linear', -20);
g_dBi = g_az + g_el - pat.max_gain_dBi;
end
%
rx_gain_amp = sqrt(10^(g_dBi/10));
RxOut.space_loss_amp(k, rx, :, :, :) = RxOut.space_loss_amp(k, rx, :, :, :) * rx_gain_amp;
end
end
end