Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to calculate time delay estimation?

Status
Not open for further replies.

nateduong

Newbie level 3
Joined
Jan 4, 2017
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
66
I have 2 data file
TX data file:
HTML:
https://www.dropbox.com/s/xgyo6le3bcmd25r/RX.dat?d...

RX data file:
HTML:
https://www.dropbox.com/s/0nmhw6mpgh7upmv/TX.dat?d...

and easily compute the delay from this code:


Code:
clear all; close all; format long;

%% initial values:
nsamps          = inf;
nstart          = 0;
Fs              = 8e6; % sample rate
flag            = 1;   % plot in the for loop
c               = 3e8; % speed of light

%% input data
file_tx         = 'TX.dat';
file_rx         = 'RX.dat';
x_tx            = readcplx(file_tx, nsamps,nstart); 
x_rx            = readcplx(file_rx, nsamps,nstart); 
data_time       = 10; % second % we can set time base on the length of vector x_rx
data_time       = floor((length(x_rx) - 8e5)/Fs) * 10;

factor          = data_time/10;
matric          = reshape(x_rx, [Fs/data_time*factor, data_time + 1]); 
matric          = matric';
size_of         = size(matric);
len             = 1:size_of(1);
delay           = zeros(1, data_time + 1);

%% time delay calculation:
aa      = zeros(1, length(matric(1,:)) - length(x_tx));
signal1 = [x_tx aa];    

for i = 1: 1%size_of(1)
    
    signal2                 = matric(i,:);
    [cc_correlation,lag]    = xcorr(signal1, signal2);
    [cc_maximum, cc_time]   = max(abs(cc_correlation));
    cc_estimation           = abs(length(signal1) - cc_time);
    delay(i)                = cc_estimation/Fs; % in second
    
    lagDiff                 = lag(cc_time);
    s2                      = signal2(abs(lagDiff)+1:end);
    t2                      = (0:length(s2)-1)/Fs;    
end
%%
fprintf('\n Done! \n\n');



Code:
function x = readcplx(filename,nsamps,nstart);
fid = fopen(filename);
fseek(fid,4 * nstart,'bof');
y = fread(fid,[2,inf],'short');
fclose(fid);
x = complex(y(1,:),y(2,:));

So I have matrix of delay:


delay = 0.010346125000000 0.010349000000000 0.0103498750000000.010349000000000 0.010349750000000 0.010349750000000 0.010349750000000 0.010349750000000 0.010348875000000 0.010348875000000 0.010348875000000


I want to make sure I did right or wrong?

Also, when I compute the xcorr, I see it weird from the plot, so I can not define the max of the yaxis. Do you see anything wrong?

1.PNG

I hope everyone can help me out?

Thank you very much.
 

The links to the data you provided don't seem to be full. Could you post the whole thing?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top