Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. N = 20000; % # symbols
  2. h = [1 0.45 -0.2]; % channel impulse response
  3. h = h/norm(h);
  4. Le = 20; % equalizer length
  5. mu = 1E-3; % step size
  6. snr = 30; % snr in dB
  7. M = 10; % oversample rate
  8.  
  9. tx_type = "bpsk"; % select modulation type here "bpsk" or "fsk"
  10.  
  11. if strcmp(tx_type, "bpsk")
  12. s0 = round( rand(N,1) )*2 - 1; % BPSK signal
  13. s0M = zeros(N*M,1); % oversampled BPSK signal
  14. k = 1;
  15. for i=1:M:N*M
  16. s0M(i:i+M-1) = s0(k);
  17. k ++;
  18. end
  19. end
  20.  
  21. if strcmp(tx_type, "fsk")
  22. tx_bits = round(rand(1,N));
  23.  
  24. % continuous phase FSK modulator
  25.  
  26. w1 = pi/4;
  27. w2 = pi/2;
  28. tx_phase = 0;
  29. tx = zeros(M*N,1);
  30.  
  31. for i=1:N
  32. for k=1:M
  33. if tx_bits(i)
  34. tx_phase += w2;
  35. else
  36. tx_phase += w1;
  37. end
  38. tx((i-1)*M+k) = exp(j*tx_phase);
  39. end
  40. end
  41.  
  42. s0M = real(tx);
  43. end
  44.  
  45. s = filter(h,1,s0M); % filtered signal
  46.  
  47. % add Gaussian noise at desired snr
  48.  
  49. n = randn(N*M,1);
  50. vs = var(s);
  51. vn = vs*10^(-snr/10);
  52. n = sqrt(vn)*n;
  53. r = s + n; % received signal
  54.  
  55. e = zeros(N*M,1); % error
  56. w = zeros(Le,1); % equalizer coefficients
  57. w(Le)=1; % actual filter taps are flipud(w)!
  58.  
  59. yd = zeros(N*M,1);
  60.  
  61. for i = 1:N*M-Le,
  62. x = r(i:Le+i-1);
  63. y = w'*x;
  64. yd(i)=y;
  65. e(i) = y^2 - 1;
  66. w = w - mu * e(i) * y * x;
  67. end
  68.  
  69. np = 100; % # sybmols to plot (last np will be plotted); np < N!
  70.  
  71. figure(1); clf;
  72. subplot(311), plot(e.*e), title('error')
  73. subplot(312), stem(conv(flipud(w),h)), title('equalized channel impulse response')
  74. subplot(313);
  75. plot(1:np,s0M(N-np+1:N),1:np,yd(N-np+1-Le+1:N-Le+1))
  76. title('transmitted and equalized signal'), legend('transmitted','equalized'), axis([0,np,-1.5,2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement