The primary point causing Just Noise is that you have
Basically you don't have signal.
Let's build the signal :
close all;clear all;clc;
I am going to build the pulse, add noise, and you can take it from there :
1.- Start Parameters
I have divided fc and fs by 1e6 because before generating lots of samples we have to make it fly.
Upsacling again is easy.
fc=1e4; % [Hz] carrier frequency
c=3e8; % [m/s] speed of light
lambda=c/fc; % [m] wavelength
PRF=20; % [Hz] Pulse Repetition Frequency
PRI=1/PRF; % [s] Pulse Repetition Interval
% fs=1e9 and fc=10e9 causes strong alias.
% The resulting signal is meaningless with such low sampling frequency.
fs=1e2*fc; % [Hz] sampling frequency
dt=1/fs; % [s] time step
D=.3 % duty cycle
t=dt*[0:dt:1]; % ?? :(PRI/122)-3*ts; % only sampling to 4096 samples
B= 10; % [Hz] bandwidth
Tp=300/B % setting the time bandwith product to 300
r=(c.*t)./2; % chirp rate
N= 20 % number of pulses
T = length(t);
Distance Velocity Acceleration Parameters
Not using the following lines :
% v= linspace((-lambda*PRF/4),(lambda*PRF/4),N);
% V0 =vmax*(-1+2*rand(1,1)); % target velocity
% Rmin= 1;Rmax= 33; % to avoid wrap around
% R0 =Rmin + (Rmax-Rmin).*abs(rand(1,1)); % target range
% Rcell=round((2*R0/(c*dt))+1); % target range based on cell number
% Vcell=round((N-1).*(V0+(vmax+1))./(2*(vmax+1))+1); % target velocity based on cell number
% a0= 0; % target acceleration
% grid on;xlabel('t');ylabel('st');title('st : transmitted signal on antenna')
2.- Single Pulse, no modulation, no chirp
plot(t1,p1); grid on; xlabel('t');ylabel('p1');title('Single Pulse : No Modulation')
T1 is not
T1=t1(end) % = .04999 % [s] single pulse cycle
t_stop - t_start there's a tiny
dt related difference that upon several cycles derails the pulse signal.
3.- Fix for the amount of pulses
Since you have decided the amount of pulses needed (I set it to 20, to simplify) change it accordingly, in your initial script
t(end)=0.04096. If you need N pulses then t has to last at least
N*T1*PRI = 1 second.
T1d=t1(floor(D*numel(t1)))+dt % [s] pulse duty cycle
4.- Pulse Modulation
It's good practice to generate frequency-changing pulses with adjacent samples avoiding abrupt trips.
One way to do this is to step the chirp frequency
fm=linspace(f1,f2,5) % [Hz]
Tm=1./fm % [s]
How many samples available per duty cycle
How many samples available per frequency step
If just 1 cycle per frequency step, it would be these amount of samples per frequency step
How many cycles per frequency step
Round down to have smooth transitions between frequency steps.
This can be improved to make 1st derivative to also have smooth transitions.
How many cycles per frequency step
Assigning same amount of samples, kind of, to each frequency step
for loop prevents the amplitude of adjacent step frequencies having sharp changes.
if diff_step_end>0 & last_sample>=0 % climbing and last_sample>=0
if diff_step_end>0 & last_sample<=0 % climbing and last_sample<=-sin(2*pi*fm(1)*dt)
if diff_step_end<0 & last_sample>=0 % falling and last_sample>=sin(2*pi*fm(1)*dt)
if diff_step_end<0 & last_sample>=0 % falling and last_sample<=0
while s_tep(end-k2)>-sin((2*pi*fm(1)*dt)) % climbing and last_sample>=0 : too many samples
while sin(2*pi*fm(s1)*nt2(s1)*(Nsamples_per_cycle(s1)+k2)*dt)<-sin((2*pi*fm(1)*dt)) % climbing and last_sample<=0 : not enough samples
while sin(2*pi*fm(s1)*nt2(s1)*(Nsamples_per_cycle(s1)+k2)*dt)<-sin((2*pi*fm(1)*dt)) % falling and last_sample>0 : not enough samples
while abs(s_tep(end-k2))>sin((2*pi*fm(1)*dt)) % falling and last_sample<=0 : too many samples
grid on; xlabel('t');ylabel('st0');title('Single Pulse : MODULATED, No Targets')
Another way that I am not getting into in this answer, would be keeping constant the amount of cycles per frequency step.
5.- Assembling Duty Cycle and Guard Interval
To discern target locations, for each pulse, whatever is received after the Duty Cycle has to be ignored.
This is the time reference for the Guard Interval
time reference for a complete pulse
6.- Transmitted power
Ptx=mean(st0.*conj(st0)) % ~.5W transmission
grid on;xlabel('t');ylabel('|pulse|');title('Single Pulse, Guard Interval off')
I am not going to implement doppler shift caused by the random velocities that you generate in the question.
If interested please let me know, or ask another question, and I will answer accordingly.
Here you could concatenate multiple pulses
However a radar design has to start with discerning what max range is not going to cause false alarms.
Delayed signals beyond one pulse should be weak enough to neglect them. This also meaning, whatever happens in one pulse cycle should not spill over to time adjacent pulses.
7.- Received Signal : Let's assume for instance 30dB down
L_channel=-20 % [dB]
Because I have switched off the pulse throughout the guard interval and no targets yet, for the following calculation there's no need to include the zero samples.
Just keep the transmitter on in the Guard Interval, then when no targets, one can use the entire pulse, not just the duty cycle, for 'dry' (no targets) calculations.
8.- Adding noise
45dB is a good SNR so it's probably on transmitting antenna.
Changing 45dB to 10dB more realistic, MEASURE SNR ON RECEPTION
sr received pulse
With Communications Toolbox
Without Communications Toolbox
SNR=10 % [dB] RECEPTION
Pn=Psr/10^(SNR/10) % signal power
n_var=Pn % AWGN noise standard deviation is noise power (Z0=1)
check, it should be the expected 10dB on reception
grid on;xlabel('t');ylabel('|pulse|');title('Single Pulse, received')
axis([0 t2(end) -1.2 1.2])
9.- If you do not add further comment I am going to stop here and you can link from this point on with your code, starting with the following lines.
srrW=fft((srr(h,:)./norm(srr(h,:))),,2); % FFT of normalised return echo
stW=conj(fft(st./norm(st))); %fft of normalised transmitted echo
- NO ALIAS
- a concise time reference
- a working pulse
- Clear difference between duty cycle and the guard interval
Now you can add targets as well as pick up echos, and you can change the SNR on Reception.
NOW take the entire cycle : Duty Cycle and Guard Interval to calculate SNR and detect because target reflections should arrive within the Guard Interval of same pulse that has caused them.