Advertisement
Guest User

16-QAM transmitter and receiver without channel

a guest
Apr 10th, 2013
943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.22 KB | None | 0 0
  1. M = 16; % QAM order
  2. fs = 16000; % sampling frequency in Hz
  3. Ts = 1/fs; % sampling interval in s
  4. fc = 1000; % carrier frequency in Hz (must be < fs/2 and > fg)
  5. Rs = 100; % symbol rate
  6. Ns = 20; % number of symbols
  7.  
  8. x = randint(Ns,1,M);
  9. y = modulate(modem.qammod(M),x);
  10.  
  11. L = fs/Rs; % oversampling factor
  12.  
  13. % Impulse shaping
  14. y_a = reshape(repmat(y', L, 1), 1, length(y)*L);
  15.  
  16. %% Modulation
  17. Q=real(y_a);
  18. I=imag(y_a);
  19. t = 0 : Ts : (length(y_a) - 1) * Ts;
  20. C1 = I .* sin(2*pi * fc * t);
  21. C2 = Q .* cos(2*pi * fc * t);
  22. s = C1 + C2;
  23.  
  24. %% Demodulation
  25. r_I = s .* sin(2*pi * fc * t);
  26. r_Q = s .* cos(2*pi * fc * t);
  27.  
  28. %% Filter
  29.  
  30. % Design filter with least-squares method
  31. N     = 50;           % Order
  32. Fpass = Rs/2;         % Passband Frequency
  33. Fstop = 2*fc - Rs/2;  % Stopband Frequency
  34. Wpass = 1;            % Passband Weight
  35. Wstop = 1;            % Stopband Weight
  36.  
  37. % Calculate the coefficients using the FIRLS function.
  38. b  = firls(N, [0 Fpass Fstop fs/2]/(fs/2), [1 1 0 0], [Wpass Wstop]);
  39.  
  40. % Filtering
  41. w_I = filter(b, 1, r_I);
  42. w_Q = filter(b, 1, r_Q);
  43.  
  44. %% Sampling
  45. u_I = downsample(w_I, L, L/2);
  46. u_Q = downsample(w_Q, L, L/2);
  47.  
  48. figure;
  49. plot(r_I); hold on;
  50. plot(w_I,'r'); hold off;
  51. figure;
  52. plot(u_I, u_Q, '.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement