-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathCA_CFAR_1D.m
66 lines (44 loc) · 1.56 KB
/
CA_CFAR_1D.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% Implement 1D CFAR using lagging cells on the given noise and target scenario.
% Close and delete all currently open figures
close all;
% Data_points
Ns = 1000;
% Generate random noise
s=abs(randn(Ns,1));
%Targets location. Assigning bin 100, 200, 300 and 700 as Targets with the amplitudes of 8, 9, 4, 11.
s([100 ,200, 350, 700])=[8 15 7 13];
%plot the output
plot(s);
% TODO: Apply CFAR to detect the targets by filtering the noise.
% 1. Define the following:
% 1a. Training Cells
T = 12;
% 1b. Guard Cells
G = 4;
% Offset : Adding room above noise threshold for desired SNR
offset=5;
% Vector to hold threshold values
threshold_cfar = [];
%Vector to hold final signal after thresholding
signal_cfar = [];
% 2. Slide window across the signal length
for i = 1:(Ns-(G+T+1))
% 2. - 5. Determine the noise threshold by measuring it within the training cells
noise_level =sum(s(i:i+T-1));
% 6. Measuring the signal within the CUT
threshold = (noise_level/T)*offset;
threshold_cfar=[threshold_cfar,{threshold}];
signal=s(i+T+G);
% 8. Filter the signal above the threshold
if (signal<threshold)
signal=0;
end
signal_cfar = [signal_cfar, {signal}];
end
% plot the filtered signal
plot (cell2mat(signal_cfar),'g--');
% plot original sig, threshold and filtered signal within the same figure.
figure,plot(s);
hold on,plot(cell2mat(circshift(threshold_cfar,G)),'r--','LineWidth',2)
hold on, plot (cell2mat(circshift(signal_cfar,(T+G))),'g--','LineWidth',4);
legend('Signal','CFAR Threshold','detection')