How to calculate standard deviation?

In summary, the author is trying to determine the standard deviation of the time delay estimates produced by the xcorr algorithm. He has two signals, each of which represents 20 measurements. He will process the signals and calculate the standard deviation. He finds that the expected standard deviation is nanoseconds but that he actually gets microseconds. He is not sure why this is happening, and he needs help from someone more experienced.
  • #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>
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
  • #2
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
  • #3
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.
 
  • #4
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?
 
  • #5
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:
 

1. What is the formula for calculating standard deviation?

The formula for standard deviation is:
SD = √(Σ(x - μ)^2 / N)
Where SD is the standard deviation, Σ is the sum of all values, x is each individual value, μ is the mean, and N is the total number of values.

2. Why is standard deviation important in data analysis?

Standard deviation is important because it measures the variability or spread of a set of data. It allows us to understand how much the data points deviate from the mean, and therefore gives us a better understanding of the data's distribution and overall pattern.

3. How do you interpret the value of standard deviation?

A low standard deviation indicates that the data points are close to the mean, while a high standard deviation indicates that the data points are spread out over a wider range. In other words, a lower standard deviation means the data is more consistent, while a higher standard deviation means the data is more diverse.

4. Can standard deviation be negative?

No, standard deviation cannot be negative. It is always a positive value or zero. A negative value would indicate that the data points are further away from the mean than the mean itself, which is not possible.

5. How does sample size affect the standard deviation?

The larger the sample size, the more accurate the standard deviation will be. As the sample size increases, the variability of the data becomes more precise, resulting in a more reliable measure of standard deviation.

Similar threads

  • Electrical Engineering
Replies
14
Views
2K
Replies
24
Views
2K
  • Electrical Engineering
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Back
Top