How can solve this error when using phased.CFAR, please? ("Error using step Expected Idx to be an array with all of the values <= 1)

Hi All,
I've been trying to do a simple cfar algorithm on a simulated set of signal + whie gaussian noise. However I encounter the following error. I did dig down into the functions to understand the issue, but i can't seem to figure it out. It doesn't make sense to me. I am new to Radar DSP. Any help is really appreciated.
Code:
clc;clear;clf
fs = 500e9; % sampling frequency
t_max = 1e-10; % signal length
t_vec = 0:1/fs:t_max; % time vector
L_tr = length(t_vec);
L = 5000; % total simulated length
Pfa = 1e-3; % probability of false alarm aimed
noise_power = 20; % dB
signal_power = 40; % dB
snr = signal_power - noise_power;
noise_sigma_sq = 10^(noise_power/10);
Th = -noise_sigma_sq*log(Pfa); % threshold calculated based on pfa
loc1 = 1000; % location of spurious signal 1
loc2 = 2500; % location of spurious signal 2
% two triangular spurious signals
tr1 = 1.00*[zeros(1,(loc1-1)), 1+sawtooth(2*pi*1e10*t_vec, 0.5), zeros(1,(L-loc1-L_tr+1))];
tr2 = 0.25*[zeros(1,(loc2-1)), 1+sawtooth(2*pi*1e10*t_vec, 0.5), zeros(1,(L-loc2-L_tr+1))];
tr = tr1+tr2;
% add white gaussian noise to data
sig = awgn(tr, snr);
sig_db = 10*log10(abs(sig/1e-3)); % use of dB level is for visuvalization only
% plotting to see good SNR
plot(abs(sig_db))
yline(10*log10(Th),'r--')
xlabel 'Sample (time)'
ylabel 'Amplitude (dB level)'
grid on
ylim([0 40])
legend ('Signal', 'Fixed Threshold')
% cfar detector
cfar = phased.CFARDetector('NumTrainingCells',20,'NumGuardCells',2, ...
'ProbabilityFalseAlarm',Pfa,'OutputFormat','Detection index');
cutid = 1:length(sig_db);
x_det = cfar(abs(sig_db),cutid); % error comes here (%using abs, or dB level did not change the error)
Error using step
Expected Idx to be an array with all of the values <= 1.

Error in sigdatatypes.validateIndex (line 36)
validateattributes(x,type,varargin{2},funcname,varname);

Error in phased.CFARDetector/stepImpl (line 278)
sigdatatypes.validateIndex(CUTIdx,'step','Idx',...

 Accepted Answer

If you pass to cfar a column vector as the first argument, then it runs without error:
clc;clear;clf
fs = 500e9; % sampling frequency
t_max = 1e-10; % signal length
t_vec = 0:1/fs:t_max; % time vector
L_tr = length(t_vec);
L = 5000; % total simulated length
Pfa = 1e-3; % probability of false alarm aimed
noise_power = 20; % dB
signal_power = 40; % dB
snr = signal_power - noise_power;
noise_sigma_sq = 10^(noise_power/10);
Th = -noise_sigma_sq*log(Pfa); % threshold calculated based on pfa
loc1 = 1000; % location of spurious signal 1
loc2 = 2500; % location of spurious signal 2
% two triangular spurious signals
tr1 = 1.00*[zeros(1,(loc1-1)), 1+sawtooth(2*pi*1e10*t_vec, 0.5), zeros(1,(L-loc1-L_tr+1))];
tr2 = 0.25*[zeros(1,(loc2-1)), 1+sawtooth(2*pi*1e10*t_vec, 0.5), zeros(1,(L-loc2-L_tr+1))];
tr = tr1+tr2;
% add white gaussian noise to data
sig = awgn(tr, snr);
sig_db = 10*log10(abs(sig/1e-3)); % use of dB level is for visuvalization only
% plotting to see good SNR
plot(abs(sig_db))
yline(10*log10(Th),'r--')
xlabel 'Sample (time)'
ylabel 'Amplitude (dB level)'
grid on
ylim([0 40])
legend ('Signal', 'Fixed Threshold')
% cfar detector
cfar = phased.CFARDetector('NumTrainingCells',20,'NumGuardCells',2, ...
'ProbabilityFalseAlarm',Pfa,'OutputFormat','Detection index');
cutid = 1:length(sig_db);
x_det = cfar(abs(sig_db(:)),cutid)
x_det = 1×0 empty double row vector

More Answers (0)

Products

Release

R2023b

Asked:

on 2 Feb 2024

Commented:

on 2 Feb 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!