nateduong
Newbie level 3

I have 2 data file
TX data file:
RX data file:
and easily compute the delay from this code:
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?

I hope everyone can help me out?
Thank you very much.
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?

I hope everyone can help me out?
Thank you very much.