I implemented a version of a CFAR average in MATLAB but it's 'slow' and I need to speed it up. I included the pseudo code and logic below. I used a nested for loop to calculate the moving average but this is no good since I want to run this on hundreds of millions of sample points. Does anyone have any methods for making this run faster? As long as it doesn't use a nested for loop, anything is better. Any suggestions for using just one for loop?
This is the picture I used to calculate the lead and lag training windows. I am looping though all the points in my range window and calculating average lead and lag on the training samples for the cell under test CUT. For the CUT near the start or end of the range window, I used either the lead or lag and used double the training size. Again this is pseudo code so I don't care about saving off my values. Overwriting values is fine for now. Data is my MATLAB variable I am using to calculate the CFAR average.
Please let me know how to speed this up!
[![enter image description here]] [![enter image description here]]
range_window_length=1000; G=2; T=50; For n=1:range_window_length % Condition if CUT is less than G+T if n<G+T lag_cum=0 for i=n+G:n+G+T*2 %use 2 times T lag_cum=lag_cum+data(i) end % Condition if CUT is greater than than range window length minus (G+T) elseif n>range_window_length-(G+T) lead_cum for i=n-G-2*T : n-G lead_cum=lead_cum+data(i) end % middle region calculate lead and lag else lead_cum=0; for i=n-G-T:n-G lead_cum=lead_cum+data(i); end lag_cum=0; for i=n+G:n+G+T lag_cum=lag_cum+data(i); end end end : https://i.stack.imgur.com/EQAJn.png : https://i.stack.imgur.com/7cL72.png