- #1
Nate Duong
- 126
- 3
I have 2 signals:
signal1: https://www.dropbox.com/s/zr04pff9skeh8cn/TX.dat?dl=0
signal2: https://www.dropbox.com/s/h436a915dd99hln/RX1.dat?dl=0
signal2 represents for 20 measurements, each measurement combines with signal1 to get time delay estimation using xcorr.
So, I will have 20 delays and put them in the vector delay (1x20),then calculate the Standard deviation
The expectation of the Standard deviation is few nanoseconds, but I still got in microseconds, I could not figure out what are issues?
I am not sure I did right and need help from experience people, if you see something wrong or not make sense to you, please let me know.
Thank you.
<Moderator's note: please use code tabs when posting code>
signal1: https://www.dropbox.com/s/zr04pff9skeh8cn/TX.dat?dl=0
signal2: https://www.dropbox.com/s/h436a915dd99hln/RX1.dat?dl=0
signal2 represents for 20 measurements, each measurement combines with signal1 to get time delay estimation using xcorr.
So, I will have 20 delays and put them in the vector delay (1x20),then calculate the Standard deviation
The expectation of the Standard deviation is few nanoseconds, but I still got in microseconds, I could not figure out what are issues?
I am not sure I did right and need help from experience people, if you see something wrong or not make sense to you, please let me know.
Thank you.
<Moderator's note: please use code tabs when posting code>
Matlab:
format long;
%% initial values:
nsamps = inf;
nstart = 0;
Fs = 8e6; % sample rate
c = 3e8; % speed of light
%% input data
file_tx = 'TX.dat';
file_rx = 'RX1.dat';
x_tx = readcplx(file_tx, nsamps,nstart);
x_rx = readcplx(file_rx, nsamps,nstart);
%% condition for selected gain
mav_rx = maxabs(x_rx);
if ((mav_rx >= 1e3) && (mav_rx <= 1e4))
fprintf('satisfy condition! maximum absolute value inside [1000 10000] range. \n');
%% calculate the seconds of the rx data
data_time = length(x_rx)/(Fs/10) - 1; % seconds
%% split every single second window
factor = data_time/10;
matric = reshape(x_rx, [Fs/data_time*factor, data_time + 1]);
size_matric = size(matric);
delay = zeros(1, size_matric(2));
%% add noise and extend the length for x_tx = length of 1 second window of each pulse
len = size_matric(1) - length(x_tx);
tx_extend = zeros(1, len);
matric1 = matric(1:end, 1);
matric1 = matric1.';
x_tx = [x_tx matric1(length(x_tx):end-1)];
for i = 1:size_matric(2)
signal1 = x_tx;
signal2 = matric(1:end, i);
signal2 = signal2.';
[cc_correlation,lag] = xcorr(signal2, signal1);
[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 % for i = 1:size_matric(2)
else
fprintf('look and adjust the gain from RX and TX to make sure the Maximum Absolute Value (MAV) in the range of 1000 to 10000 !\n');
end % if ((mav_rx >= 1e3) && (mav_rx <= 1e4))S = std(delay);
mean1 = mean(delay);
delay1 = mean1 - delay;
SNR = 20*log(mean1/S);
%%
fprintf('\n Done! \n\n');
%%%%%%%%%%%
%%%%%%%%%%%
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,: ));
end
%%%%%%%%%%%
Last edited by a moderator: