## Hi. 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.

### Vigneshwar Dhamodharan (view profile)

on 28 May 2019
Latest activity Commented on by Vigneshwar Dhamodharan

### Vigneshwar Dhamodharan (view profile)

on 28 May 2019
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.
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; % Corresponds to 43.2kmph
%% 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)');

### Honglei Chen (view profile)

on 28 May 2019

#### 1 Comment

Vigneshwar Dhamodharan

### Vigneshwar Dhamodharan (view profile)

on 28 May 2019
Hi, I have already referred to the example prior to posting this code. I wasnt able to fully understand the codes there as there were no equations involved nor were the basics exposed in those external functions. I am trying to implement it in pure matlab without using external functions like the mentioned phasedarraytoolbox for a complete understanding.
I just want to know if my way of creating the transmit and received signal are correct, if my equation for the IF signal is correct, and if I am doing the FFT the right way.
Thank you for your time. :)