Continue to Site

# How to simulate FMCW and process Radar 2D matrix in Matlab. Problem explained.

Status
Not open for further replies.

#### vig94

##### Newbie level 1
Hi. I am a Masters Student who requires this as a first step to start my Thesis, and I am new to matlab signal processing. I have theoretical knowledge but I just started Matlab implementation of the same. Also I am completely new to the FMCW tool chain. I have to create an FMCW signal, transmit, receive and mix them to get the IF signal, and inturn get the radar 2D matrix for post processing. But I my 2nd FFT doesnt give the correct value of velocity. I set the chirp parameters and thus obtain the Vmax and Rmax values.
There are 2 IF signals created : one the theoretical, obtained from equation, and the other is obtained from mixing the received and transmitted signals and applying a Lowpass Filter. The goal is to create a radar 2D matrix (No. of samples x No. of chirps) so that I can try post processing to get the Range and velocity. I am able to get the correct range value, but the velocity is always wrong. I am unable to figure out what's wrong. I have posted the code below. Any help would be greatly appreciated.

Code Matlab M - [expand]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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
close all;
clear all;
clc;

%% Params
c=3e8;

%%% Transmit side params
f0 = 10e9;
% dR = 15e-2;
% Rmax = 7.5e3;
% dV = 0.94;
% Vmax = 7.5;

B = 1e9;
T = 1e-5;
Ns = 2048;
L = 64;

% fdmax=1/(1*T);

R1 = 70;
v1 = 50; % m/s

%% Derived Params
%----------------
% If Vmax, Rmax, dR, dV specified
% T = c/(4*Vmax*f0);
% B=c/(2*dR);
% Ns = (4*B*Rmax)/c;
% L = ceil(c/(2*f0*dV*T)) ; % No.of Chirps
%-------------------------------
%If B, T, Ns, L are specified
Vmax = c/(4*T*f0);
dR=c/(2*B);
m = B/T;
Rmax = Ns*c/(4*B);
dV = c/(2*f0*L*T);

%-------------------------------
% n=ceil(log10(Vmax));
% factor = roundn(Vmax,n)
% v1 = factor-v1;
%-------------------------------

t0 = 2*R1/c;
phi0 = 2*pi*f0*t0 - pi*m*(t0^2);
fb = 2*R1*m/c;
fd = -2*v1*f0/c;

% fif_val1 = fb + fd;           % For comparison purpose
% fif_val2 = m*t0 +f0*2*v/c;
% v1=v1-T*1e8/2;

fif_val= fb + fd;
Ts = T/Ns;
Fs = 1/Ts;

%Therefore
t=0:Ts:T-Ts;
%

%% Big time scale
time_scale = zeros(1,L*Ns);
time_scale(1:length(t)) = t(1:end);

%% For No.of chirps = L
for i=1:L-1
time_scale((i*length(t))+1:(i+1)*length(t)) = t + (T*i);
end
%  time_scale=0:Ts:T*L-Ts;

% td=1e-6;
td=2*(R1+v1.*t)/c;

% R= c*td/2
f_t = f0 + m*t;
% f_r = f0 + m*(t-td)/2;

%% For L chirps
t=time_scale;
td=2*(R1+v1.*t)/c;
f_t = repmat(f_t,1,L);

% New -----------
f_r = zeros(size(f_t));
n = ceil(t0/Ts);
f_r(n+1:end) = f_t(1:end-n);
f_r = f_r + fd;
%----------

% f_r = repmat(f_r,1,L);
f_if = f_t-f_r;
% f_if(1:n) = 0;
st = cos(2*pi.*f_t.*t);
rt = cos(2*pi.*f_r.*t);
% rt = cos(2*pi.*f_r.*(t+td));  %%%%%%%%
% rt = cos(2*pi*(f0(t-td) + m*((t-td)^2)/2));
% t = time_scale;
% st = repmat(st,1,L);
% rt = repmat(rt,1,L);
% f_t = repmat(f_t,1,L);
% f_r = repmat(f_r,1,L);
fif = rt.*st;
fif_lpf = lowpass(fif,max(f_if),2*B,'Steepness',0.8);
%% Final IF signal
fif_the = 0.5*cos(phi0 + 2*pi*fif_val.*t);
% fif_the = 0.5*cos(phi0 + 2*pi.*f_if.*t);

%% Plots
% xlimit = 2*T;
xlimit = T/2;

%-------Fig 3 For Big time scale----------%
figure(3)
subplot(511)
plot(t,st);
xlim([0 xlimit])
title("Received signal as st = cos(2*pi.*f_t.*t);")
subplot(512)
plot(t,rt);
xlim([0 xlimit])
title("Received signal as rt = cos(2*pi.*f_r.*t);")
subplot(513)
plot(t,fif);
xlim([0 xlimit])
title("IF after Mixing")
subplot(514)
plot(t,fif_lpf);
xlim([0 xlimit])
title("IF after LPF")
subplot(515)
plot(t,fif_the);
xlim([0 xlimit])
title("IF from fif_the = 0.5*cos(phi0 + 2*pi*fif_val.*t);")

figure(5)
subplot(211)
plot(t,f_t);
% xlim([0 T/10])
hold on;
grid on;
plot(t,f_r);
ylim([f0-B f0+(2*B)]);
xlim([0 T*5])
legend('f_t','f_r')
subplot(212)
plot(t,f_if);
grid on;
xlim([0 T*5])

%% Post processing
% radar_mat = reshape(fif_the,Ns,L); %% Using the Theoretical IF Signal
radar_mat = reshape(fif_lpf,Ns,L); %% Using the Mixed and LPF IF Signal

%% Window function

%% FFT
rfft = rfft./max(max(rfft)); %Normalization
rfft = rfft(1:size(rfft)/2,:);

vfft = fft(rfft.*window_2D',[],2);

%% Normalization
% normalize = vfft./max(max(vfft));
%vfft = fftshift(vfft,2)
vfft = vfft./max(max(vfft));

%% Range and Velocity vectors
R = 0:dR:Rmax-dR;
V = linspace(-Vmax, Vmax, L);

figure(4);
h=imagesc(V,R,20*log10(abs(fftshift(vfft,2))),[-60 0]);
cb = colorbar;
set(gca,'YDir','normal')
xlabel('Velocity (m/s)');
ylabel('Range (m)');

Last edited by a moderator:

Status
Not open for further replies.