0

Hi and thank you for spare some time on reading this question. I have an assignment that is to find the distance of an object from a radar by 1) convolution 2) correlation[template matching] of sent and received signals which are rectangular pulses.I should find the time where correlation or convolution is max and use t*c/2 (c is light velocity) to find the distance; BUT all of the correlation functions of matlab are giving me wrong answer. (I assume correlation means a whole different thing in this case because in my assignment there is this phrase 'using correlation aka template matching' which I don't understand.)

Here is what I've done and the distance to find is 450 m.

clc
close all;
clear;
c = 3e8;    %light velocity
ts = 1e-9;  %sampling rate
tau = 1e-6; %width of the pulses
T = 1e-5; 
t = 0:ts:T;
f2 = figure;
f1 = figure;
f3 = figure;

sentSig = rectpuls(t,tau);
subplot(2,1,1);
plot(t,sentSig,'b', 'LineWidth', 1);
xlabel('Time(s)');

td = 3e-6; %delay time of received signal
recievedSig = 0.5*rectpuls(t-td,tau); %here I just changed the height of the signal        according to my assignment
subplot(2,1,2);
plot(t,recievedSig,'r', 'LineWidth', 1);
xlabel('Time(s)');

%Convolution (this is the correct part)
subplot(2,1,1);
co = conv2(sentSig,recievedSig);
plot(tprime,co,'c','LineWidth',1);
title('Convolution of Signals');
xlabel('Time(s)');
[MAXCO,td1]=max(co);
R1 = td1*ts*c/2; %using this formula to find the distance where convolution is max
fprintf('R1 = %f m\n',R1);

Here is where i have a problem the distance is calculated as 1950.15 instead of 450.

%Correlation
figure(f2);
subplot(2,1,2);
tprime = 0:ts:2*T;
ro = normxcorr2(sentSig,recievedSig); 
plot(tprime,ro,'g','LineWidth',1);
title('Correlation of Signals');
xlabel('Time(s)');
[MAXRO,td2]=max(ro);  %td1 & td2 are supposed to be the same but they are not!
R2 = td2*ts*c/2; %using this formula to find the distance where correlation is max
fprintf('R2 = %f m\n',R2);

Any help would be very much appreciated.

Setayesh
  • 15
  • 4

0 Answers0