How to calculate standard deviation?

Click For Summary

Discussion Overview

The discussion revolves around calculating the standard deviation of time delays derived from two signals, signal1 and signal2, using cross-correlation in MATLAB. Participants are exploring issues related to unexpected results in the standard deviation calculation, which is anticipated to be in the nanosecond range but is instead yielding microseconds.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested, Homework-related

Main Points Raised

  • The original poster describes their methodology for calculating time delays using cross-correlation and expresses confusion over the unexpectedly large standard deviation results.
  • Some participants suggest presenting the signal data in more accessible formats like PDF, Word, or Excel to facilitate further analysis.
  • One participant offers to translate the MATLAB code into Excel or Visual Basic but notes the challenges posed by the .dat file format.
  • Another participant mentions the function 'readcplx' for reading .dat files and inquires if it has been tested by the original poster.
  • A participant expresses their unfamiliarity with MATLAB and indicates a preference for using Microsoft Excel and Visual Basic, stating they cannot open .dat files.

Areas of Agreement / Disagreement

There is no consensus on the best approach to resolve the issues with the standard deviation calculation, and multiple viewpoints regarding data accessibility and software preferences are present.

Contextual Notes

Participants have not resolved the underlying issues with the standard deviation calculation, and there are dependencies on the specific data formats and software capabilities discussed.

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   Reactions: 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:
 

Similar threads

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