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)
Show older comments
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)
Accepted Answer
More Answers (0)
Categories
Find more on Detection in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
