SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %EE 724 Fall 2019 Homework 8
  2.  
  3. %#ok<*UNRCH,*NBRAK,*DEFNU,*CLALL>
  4. clear('all');
  5. clc;
  6. H=struct('Number',0);
  7. %close('all');
  8.  
  9. save_figs = true;
  10. prefix = 'ee724_hw_08';
  11. BUDGE_IT = false;%plot budge style
  12.  
  13. %%%%%%%%%%%%%%%%%%
  14. tern = @(varargin) varargin{3-logical(varargin{1})}();
  15. saveas = @(varargin) tern(save_figs,@()saveas(varargin{:}),@()[]);
  16. fixForFilename = @(s)strjoin(regexp(s,'[^-A-Za-z0-9]+','split'),'_');
  17. makeFilename = @(varargin) fixForFilename(strjoin([{prefix};varargin(:)],'_'));
  18.  
  19. downsample = @(X,M) X(1:M:end);
  20. rss = @(X) sqrt(sum(abs(X).^2));
  21. %%%%%%%%%%%%%%%%%%
  22.  
  23.  
  24. %%%%%%%%%%%%%%%%%%
  25. fs_RF = 4e9;
  26. fs_IF = 5e6;
  27.  
  28. tau_p = 100e-6;
  29. Bt = 500e6;
  30.  
  31. tau_h = 102e-6;
  32.  
  33. R_res = rangeFromDelay(.1e-9);%resolution of stretch output
  34. %%%%%%%%%%%%%%%%%%
  35.  
  36.  
  37. TargetProto = @()struct('range',[],'range_rate',[]);
  38. ProblemProto = @() ....
  39.     struct('name',[],'tau_p',[],'Bt',[],'tau_h',[],...
  40.     'tgt1',TargetProto(),'tgt2',TargetProto(),...
  41.     'compensate',false);
  42.  
  43. part1t = ProblemProto();
  44. part1t.name = 'Problem 1-Test. Range-Rate=0';
  45. part1t.tau_p = 100e-6;
  46. part1t.Bt = 500e6;
  47. part1t.tau_h = 102e-6;
  48. part1t.tgt1.range      = 0;
  49. part1t.tgt1.range_rate = 0;
  50. part1t.tgt2.range      = 0.75;
  51. part1t.tgt2.range_rate = 0;
  52.  
  53. part1 = part1t;
  54. part1.name = 'Problem 1. Range-Rate=-8000';
  55. part1.tgt1.range_rate = -8000;
  56. part1.tgt2.range_rate = -8000;
  57.  
  58. part2t = part1t;
  59. part2t.name = 'Problem 2-Test. Range-Rate=0';
  60. part2t.tau_p = 200e-6;
  61. part2t.tau_h = 202e-6;
  62.  
  63. part2a = part2t;
  64. part2a.name = 'Problem 2a. Range-Rate=-8000';
  65. part2a.tgt1.range_rate = part1.tgt1.range_rate;
  66. part2a.tgt2.range_rate = part1.tgt2.range_rate;
  67.  
  68. part2b = part2a;
  69. part2b.name = 'Problem 2b. Range-Rate=-4000';
  70. part2b.tgt1.range_rate = part2b.tgt1.range_rate/2;
  71. part2b.tgt2.range_rate = part2b.tgt2.range_rate/2;
  72.  
  73. part3 = part1;
  74. part3.name = 'Problem 3. Range-Rate=-200';
  75. part3.tgt1.range_rate = -200;
  76. part3.tgt2.range_rate = -200;
  77.  
  78. part5 = part1;
  79. part5.name = 'Problem 5. Range-Rate=-8000 Compensated';
  80. part5.compensate = true;
  81.  
  82. data = [part1t];
  83. if BUDGE_IT
  84.     data = data([]);
  85. end
  86. data(end+1) = part1;
  87.  
  88. if ~BUDGE_IT
  89.     data(end+1) = part2t;
  90. end
  91. data = [data, [part2a,part2b,part3,part5]];
  92.  
  93. Ps1 = 1;
  94. Ps2 = 0.5;
  95.  
  96. for i=1:length(data)
  97.     problem = data(i);
  98.    
  99.     name  = problem.name;
  100.     tau_p = problem.tau_p;
  101.     Bt    = problem.Bt;
  102.     tau_h = problem.tau_h;
  103.    
  104.     [Vo_f,v_return,range] = generateStretchProcessor(tau_p,Bt,tau_h,fs_RF,fs_IF,...
  105.         R_res);
  106.  
  107.     R1  = problem.tgt1.range;
  108.     Rd1 = problem.tgt1.range_rate;
  109.     range_1 = @(t) (R1+Rd1*t);
  110.     tgt1 = v_return(Ps1,range_1);
  111.    
  112.     R2  = problem.tgt2.range;
  113.     Rd2 = problem.tgt2.range_rate;
  114.     range_2 = @(t) (R2+Rd2*t);
  115.     tgt2 = v_return(Ps2,range_2);
  116.    
  117.     vrx_1 = @(t)tgt1(t);
  118.     vrx_2 = @(t)tgt1(t)+tgt2(t);
  119.    
  120.     if problem.compensate
  121.         compensation = range_1;
  122.     else
  123.         compensation = [];
  124.     end
  125.    
  126.     Vo1 = Vo_f(vrx_1,compensation);
  127.     Vo2 = Vo_f(vrx_2,compensation);
  128.    
  129.     range_delay = delayFromRange(range);
  130.     idx = (-15e-9<=range_delay & range_delay<=15e-9);
  131.     H=figure(H.Number+1);clf;
  132.     if ~BUDGE_IT
  133.         hold('on');
  134.     end
  135.     plot(range_delay(idx)*1e9,abs(Vo1(idx)));
  136.     h=xlabel('Range delay (ns)');h.FontSize=11;
  137.     h=ylabel('|V_o(\tau)|');h.FontSize=11;
  138.     grid('on');
  139.     axis('tight');
  140.     if BUDGE_IT
  141.         h=title(['\bf' name ': Stretch Processor Output for One Target']);h.FontSize=12;
  142.         saveas(H,makeFilename(name,'1_tgt'),'png');
  143.     end
  144.    
  145.     if BUDGE_IT
  146.         H=figure(H.Number+1);clf;
  147.     end
  148.     plot(range_delay(idx)*1e9,abs(Vo2(idx)));
  149.     h=xlabel('Range delay (ns)');h.FontSize=11;
  150.     h=ylabel('|V_o(\tau)|');h.FontSize=11;
  151.     grid('on');
  152.     axis('tight');
  153.     if BUDGE_IT
  154.         h=title(['\bf' name ': Stretch Processor Output for Two Targets']);h.FontSize=12;
  155.         saveas(H,makeFilename(name,'2_tgt'),'png');
  156.     end
  157.    
  158.     if ~BUDGE_IT
  159.         legs = {'1 Target','2 Targets'};
  160.         legend(legs,'Location','Best');
  161.         h=title(['\bf' name ': Stretch Processor Outputs']);h.FontSize=12;
  162.         saveas(H,makeFilename(name,'both_tgt'),'png');
  163.     end
  164.  
  165. end
  166.  
  167. %%%%%%%%%%%%%%%%%%%%%%%%%
  168. function [Vo_f,v_return,range] = generateStretchProcessor(tau_p,Bt,tau_h,fs_RF,fs_IF,R_res)
  169.     tern = @(varargin) varargin{3-logical(varargin{1})}();
  170.     if nargin<6 || isempty(R_res)
  171.         %resolution of stretch output
  172.         R_res = .015; %meters
  173.     end
  174.     tau_res = delayFromRange(R_res);
  175.    
  176.     Ts_RF = 1/fs_RF;
  177.     Ts_IF = 1/fs_IF;
  178.    
  179.     %Transmit and return signal
  180.     alpha = Bt/tau_p;
  181.     v_tx = genLFM(tau_p,Bt);
  182.     v_return = @(Ps,R) @(t)sqrt(Ps)*v_tx(t-delayFromRange(R(t)));
  183.    
  184.     % De-ramp system
  185.     tau_m = 0;%assume tau_m = 0
  186.     Bh = Bt*tau_h/tau_p; %larger bandwidth because it runs for longer
  187.     h_s = genLFM(tau_h,Bh);
  188.     h_s = @(t,R) h_s(t-tern(nargin<2 || isempty(R),@()0,@()delayFromRange(R(t))));
  189.    
  190.     % Implement the de-ramp mixer by forming vo(t) = r*(t)hs(t).
  191.     mixer = @(r,t,R)conj(r(t)).*h_s(t,R);
  192.    
  193.     Nif = ceil(fs_IF/(alpha*tau_res));
  194.  
  195.     M_if_from_rf = ceil(fs_RF/fs_IF);
  196.    
  197.     ifFromRf = @(x) downsample(x,M_if_from_rf);
  198.    
  199.     Nrf = M_if_from_rf * Nif;
  200.    
  201.     tau = ([0:Nrf-1]-Nrf/2)*Ts_RF;
  202.     T0 = max(tau(:))-min(tau(:)); %#ok<NASGU>
  203.  
  204.     k = 1/(tau_p);
  205.     vo_rf = @(r,R) k*mixer(r,tau,R);
  206.     vo_if = @(r,R) ifFromRf(vo_rf(r,R));
  207.  
  208.     % 6. Process the down-sampled signal through the FFT. This generates Vo(f).
  209.     % Don’t forget the fftshift to center the FFT output at f = 0.
  210.     % Scale the FFT output by [τp/(0.25*10−9)]/(4000/5) to normalize
  211.     % the peak to 1.0 when you use the r(t) with the single pulse centered
  212.     % at R = 0. The term in brackets is the number of samples of vo(t)
  213.     % into the ADC and the overall expression is the number of samples in
  214.     % vo(t) after the ADC.
  215.     Vo0 = Ts_IF;
  216.     Vo_f = @(r,R) fftshift(fft(vo_if(r,tern(nargin<2,@()[],@()R))))*Vo0;
  217.    
  218.     f = fs_IF/2*linspace(-1,1,Nif);    
  219.     range_delay = tau_m+f/alpha;
  220.     range = rangeFromDelay(range_delay);
  221. end    
  222. %%%%%%%%%%%%%%%%%%
  223.  
  224. %%%%%%%%%%%%%%%%%%
  225. %%%%%%%%%%%%%%%%%%
  226.  
  227. %%%%%%%%%%%%%%%%%%
  228. function [X]= rect(t,T)
  229.     %Simple window function centered at 0, with width T, and height 1
  230.     T = T/2;
  231.     t = abs(t/T);
  232.     X = 1.*(-1<=t & t<=+1);
  233. end
  234.  
  235. function [f] = genLFM(T,B,w)
  236.    %generates an LFM function that is centered at 0
  237.    % with width T
  238.    % bandwidth B
  239.    % and windowed by w
  240.    if nargin<3
  241.        w = @rect;
  242.    end
  243.    a = B/T;
  244.    f = @(t) exp(1j*pi*a*t.^2).*w(t,T);
  245. end
  246.  
  247. function [h] = genMatchedFilter(v)
  248.     %generates the matched filter function given function v
  249.     h = @(t) conj(v(-t));
  250. end
  251.  
  252. function [tau] = delayFromRange(R)
  253.     SPEED_OF_LIGHT = 3e8;
  254.     tau = 2*R/SPEED_OF_LIGHT;
  255. end
  256.  
  257. function [R] = rangeFromDelay(tau)
  258.     SPEED_OF_LIGHT = 3e8;
  259.     R = SPEED_OF_LIGHT/2*tau;
  260. end
  261. %%%%%%%%%%%%%%%%%%
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top