testing.asv
上传用户:doryuen
上传日期:2013-10-30
资源大小:23k
文件大小:7k
源码类别:

通讯/手机编程

开发平台:

Matlab

  1. %=============================================================================%
  2. %=                         TOA UWB ALGORITHM                                 =%
  3. %=                                                                           =%
  4. %= Programmed by Jasurbek Khodjaev                                           =%
  5. %= Yeungnam University Mobile Communication Lab.                             =%
  6. %= MCL 2006                                                                  =%
  7. %=============================================================================%
  8. clear all;
  9. clc;
  10. %--------------- Initialization -----------------------------------------
  11. %-------------------------------------------
  12. % Speed of Light
  13. light_speed = 3e8;
  14. % Coordinates of APs
  15. AP = [0 0; 0 10; 10 0]; % in meters
  16. % Number of Access Points (AP)
  17. num_ap = length(AP);
  18. % Tag's initial coordinate
  19. % Tag = [5 4];
  20.     
  21.     
  22. % Pulse shape
  23. pulse_order = 1; % 0-Gaussian pulse, 1-First derivative of Gaussian pulse, 2 - Second derivative;
  24. % Number of bits
  25. num_bits = 100;
  26. % Pulse repetition interval, PRI
  27. pri = 200e-9;
  28. % The SNR range (in dB)
  29. EbNo = -15;
  30. fs = 10e9; %sample rate-10 times the highest frequency in GHz
  31. ts = 1/fs; %sample period
  32. t = [(-0.5E-9):ts:(0.5E-9)]; %vector with sample instants
  33. t1 = .5E-9; %pulse width(0.5 nanoseconds)
  34. %-------------------------------------------------------------------------
  35. %----------------- PRI -------------------------------------------
  36. A =-1;%positive value gives negative going monopulse;neg value gives
  37.    %positive going monopulse
  38. [y] = monocycle(fs, ts, t, t1, A, pulse_order); % Generate Gaussian pulse
  39. n_pulse_pri = round(pri/ts);               % Sampling of PRI
  40. sig = zeros(1,n_pulse_pri);    
  41. sig(1:length(y)) = y;                 % One pulse in one PRI
  42. %-----------------------------------------------------------------
  43. shift_const = 40;
  44. kkk = 0;
  45. % for EbNo = -15:5:5
  46.     kkk = kkk + 1;
  47.     
  48.         % Tag's initial coordinate
  49.     a = round(rand * 10);
  50.     b = round(rand * 10);
  51.     Tag = [a b];
  52.     
  53. % Distance calculation between each AP and the Tag, IDEAL case
  54. for ii = 1:num_ap
  55.     dist_ap_tag(ii) = dist_t(AP(ii,:), Tag);
  56.     % Time from each AP to Tag
  57.     time_ap_tag(ii) = dist_ap_tag(ii)/light_speed;
  58. end
  59.     %++++++++++++++++ TRANSMISSION +++++++++++++++++++++++++++++++
  60.             noise_var   = 10^(-EbNo/10);
  61. %     y=y/std([y zeros(1,4000-length(y))]);
  62.     for jj = 1:num_bits
  63.             % From TAG to AP1
  64.             del_sample_ap_tag1 = round(time_ap_tag(1)/ts);
  65.             xx1 = zeros(1,del_sample_ap_tag1);
  66.             del_sig_ap1_tag(jj,:) = [ sig(1:end-length(xx1)) xx1];
  67.             h1 = uwb_channel(dist_ap_tag(1));
  68.             h1=[zeros(1,del_sample_ap_tag1) h1];
  69.             h1=h1+randn(1,length(h1)) .* sqrt(noise_var)*std(h1);
  70.             
  71.             conv_data1 = conv(del_sig_ap1_tag(jj,:), h1);
  72.             ap1_tag_chan(jj, :) = conv_data1(1:length(sig));
  73.             % From TAG to AP2
  74.             del_sample_ap_tag2 = round(time_ap_tag(2)/ts);
  75.             xx2 = zeros(1,del_sample_ap_tag2);
  76.             del_sig_ap2_tag(jj,:) = [ sig(1:end-length(xx2)) xx2];
  77.             h2 = uwb_channel(dist_ap_tag(2));
  78.             h2=[zeros(1,del_sample_ap_tag2) h2];
  79.             h2=h2+randn(1,length(h2)) .* sqrt(noise_var)*std(h2);
  80.             
  81.             conv_data2 = conv(del_sig_ap2_tag(jj,:), h2);
  82.             ap2_tag_chan(jj, :) = conv_data2(1:length(sig));
  83.             
  84.             % From TAG to AP3
  85.             del_sample_ap_tag3 = round(time_ap_tag(3)/ts);
  86.             xx3 = zeros(1,del_sample_ap_tag3);
  87.             del_sig_ap3_tag(jj,:) = [ sig(1:end-length(xx3)) xx3];
  88.             h3 = uwb_channel(dist_ap_tag(3));
  89.             h3=[zeros(1,del_sample_ap_tag3) h3];
  90.             h3=h3+randn(1,length(h3)) .* sqrt(noise_var)*std(h3);
  91.             
  92.             conv_data3 = conv(del_sig_ap3_tag(jj,:), h3);
  93.             ap3_tag_chan(jj, :) = conv_data3(1:length(sig));
  94.             jj
  95. %     end
  96.     %-------------------------------------------------------
  97.     % Additive White Gaussian Noise (AWGN) Channel ---------
  98. %     noise_var   = 10^(-EbNo/10);
  99. %     for jj = 1:num_bits
  100.         ap1_tag_chan_wgn(jj,:) = ap1_tag_chan(jj,:) + 0*std([y zeros(1,2000-length(y))])* randn(1,length(ap1_tag_chan(jj,:))) .* sqrt(noise_var);
  101.         ap2_tag_chan_wgn(jj,:) = ap2_tag_chan(jj,:) + 0*std([y zeros(1,2000-length(y))])*randn(1,length(ap2_tag_chan(jj,:))) .* sqrt(noise_var);
  102.         ap3_tag_chan_wgn(jj,:) = ap3_tag_chan(jj,:) + 0*std([y zeros(1,2000-length(y))])*randn(1,length(ap3_tag_chan(jj,:))) .* sqrt(noise_var);
  103.         
  104. %         ap1_tag_chan_wgn(jj,:) = ap1_tag_chan(jj,:)/std(ap1_tag_chan(jj,:)) + randn(1,length(ap1_tag_chan(jj,:))) .* sqrt(noise_var);
  105. %         ap2_tag_chan_wgn(jj,:) = ap2_tag_chan(jj,:)/std(ap2_tag_chan(jj,:)) + randn(1,length(ap2_tag_chan(jj,:))) .* sqrt(noise_var);
  106. %         ap3_tag_chan_wgn(jj,:) = ap3_tag_chan(jj,:)/std(ap3_tag_chan(jj,:)) + randn(1,length(ap3_tag_chan(jj,:))) .* sqrt(noise_var);
  107. %         ap1_tag_chan_wgn(jj,:) = cp0801_Gnoise1(ap1_tag_chan(jj,:), EbNo, 1);
  108. %         ap2_tag_chan_wgn(jj,:) = cp0801_Gnoise1(ap2_tag_chan(jj,:), EbNo, 1);
  109. %         ap3_tag_chan_wgn(jj,:) = cp0801_Gnoise1(ap3_tag_chan(jj,:), EbNo, 1);
  110. %         
  111.     end
  112.     
  113. % -------------------------------------------------------
  114. %     received_signl_ap1 = sum(ap1_tag_chan_wgn)/num_bits;
  115. %     xc = cp0804_corrsyn(received_signl_ap1, sig, fs);
  116. % %     cp0804_corrsyn(signal,template,fc)
  117. %     [a,delay1]=max(xc);
  118. %     TOA_1 = (length(sig) - delay1) * ts;
  119. %     
  120. %     %-----------------------------------
  121. %     
  122. %     received_signl_ap2 = sum(ap2_tag_chan_wgn)/num_bits;
  123. %     xc = cp0804_corrsyn(received_signl_ap2, sig, fs);
  124. %     [a,delay2]=max(xc);
  125. %     TOA_2 = (length(sig) - delay2) * ts;
  126. %     
  127. %     %-----------------------------------
  128. %     
  129. %     received_signl_ap3 = sum(ap2_tag_chan_wgn)/num_bits;
  130. %     xc = cp0804_corrsyn(received_signl_ap3, sig, fs);
  131. %     [a,delay3]=max(xc);
  132. %     TOA_3 = (length(sig) - delay3) * ts;
  133.     
  134.     
  135.     %------------------- AP1 receiver ------------------------------
  136.     % Correlator
  137.     received_signl_ap1 = sum(ap1_tag_chan_wgn)/num_bits;
  138.     xc1 = xcorr(y, received_signl_ap1);
  139.     [a,delay1]=max(xc1);
  140.     TOA_1 = (length(sig) - delay1) * ts;
  141. %     TOA_1 = delay1 * ts;
  142.     %------------------- AP2 receiver ------------------------------
  143.     % Correlator
  144.     received_signl_ap2 = sum(ap2_tag_chan_wgn)/num_bits;
  145.     xc2 = xcorr(y, received_signl_ap2);
  146.     [a,delay2]=max(xc2);
  147.     TOA_2 = (length(sig) - delay2) * ts;
  148. %     TOA_2 =  delay2 * ts;
  149.     %------------------- AP3 receiver ------------------------------
  150.     % Correlator
  151.     received_signl_ap3 = sum(ap3_tag_chan_wgn)/num_bits;
  152.     xc2 = xcorr(y, received_signl_ap3);
  153.     [a,delay3] = max(xc2);
  154.     TOA_3 = (length(sig) - delay3) * ts;
  155.     
  156. %     TOA_3 =  delay3 * ts;
  157.     %---------------------------------------------------------------
  158. %     time_ap_tag = time_ap_tag;
  159.     time_dur = [TOA_1 TOA_2 TOA_3];
  160.     [ex,ey]=TOA_LS(0,AP(:,1),AP(:,2),time_dur*3e8)
  161.     toa_error(1,kkk) = toa(AP, Tag, time_dur, light_speed);
  162.     kkk
  163. % end
  164. %     EbNo = -15:5:5;
  165. %     figure,plot(EbNo , toa_error);