How to calculate standard deviation?

Click For Summary
The discussion focuses on calculating the standard deviation of time delays derived from two signals using cross-correlation in MATLAB. The user has encountered unexpected results, with standard deviation values in microseconds instead of the anticipated few nanoseconds. They seek assistance in identifying potential issues in their calculations or code. The conversation also touches on the challenges of handling .dat files, with suggestions for converting data into more accessible formats like Excel. The user expresses a desire for clarity on both the standard deviation calculation and file format compatibility.
Nate Duong
Messages
125
Reaction score
4
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>
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:
Engineering news on Phys.org
Try to present the RX and TX files in pdf or word or excel. I could translate the Matlab language in excel of VB but these files are not accessible in .dat format.
 
  • Like
Likes Nate Duong
Babadag said:
Try to present the RX and TX files in pdf or word or excel. I could translate the Matlab language in excel of VB but these files are not accessible in .dat format.
I also attached this function readcplx below, it works for .dat file, have you tried it? if you tried it and did not work, i will send you the the excel format, because these are long data in complex. it will take time to convert into excel format.
 
Babadag said:
Try to present the RX and TX files in pdf or word or excel. I could translate the Matlab language in excel of VB but these files are not accessible in .dat format.
are you still there?
 
Sorry Nate Duong.At first I am not familiarized with Matlab. I'm using only Microsoft Excel and Visual Basic programs "hand made" so I cannot open .dat files nor in Excel neither in Visual Basic.Standard deviation it is a standard calculation and I could do it in Visual Basic 6 for instance if I would open the files.:sorry:
 
I am trying to understand how transferring electric from the powerplant to my house is more effective using high voltage. The suggested explanation that the current is equal to the power supply divided by the voltage, and hence higher voltage leads to lower current and as a result to a lower power loss on the conductives is very confusing me. I know that the current is determined by the voltage and the resistance, and not by a power capability - which defines a limit to the allowable...

Similar threads

  • · Replies 14 ·
Replies
14
Views
3K
Replies
24
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K