How to calculate standard deviation?

  • #1
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:

Answers and Replies

  • #2
454
124
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
126
3
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
126
3
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
454
124
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:
 

Related Threads on How to calculate standard deviation?

Replies
4
Views
2K
  • Last Post
Replies
2
Views
1K
Replies
2
Views
2K
Replies
2
Views
7K
Replies
1
Views
1K
  • Last Post
Replies
2
Views
722
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
4
Views
2K
Replies
1
Views
5K
Top