Advertisement
Narayan

signal modulation

Jan 15th, 2016
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.96 KB | None | 0 0
  1. % MATLAB Script for a Binary ASK with two Amplitude Levels
  2.  
  3. format long;
  4.  
  5. % Clear all variables and close all figures
  6. clear all;
  7. close all;
  8. clc;
  9.  
  10. % The number of bits to send - Frame Length
  11. N = 8;
  12.  
  13. % Generate the bit stream
  14. str = input ("Give me some text: ", "s");
  15. bit_stream = (dec2bin (uint8 (str), N) - "0").'(:).';
  16.  
  17. % Enter the two Amplitudes
  18. % Amplitude for 0 bit
  19. A1 = 2;
  20.  
  21. % Amplitude for 1 bit
  22. A2 = 5;
  23.  
  24. % Frequency of Modulating Signal
  25. f = 10e3;
  26.  
  27. % Sampling rate - This will define the resoultion
  28. fs = 5e6;
  29.  
  30. % Time for one bit
  31. t = [0 : 1/fs : 2/f];
  32.  
  33. % This time variable is just for plot
  34. time = [];
  35.  
  36. ASK_signal = [];
  37. Digital_signal = [];
  38.  
  39. for ii = 1: 1: length(bit_stream)
  40.    
  41.     % The Original Digital Signal
  42.     Digital_signal = [Digital_signal (bit_stream(ii)==0) * zeros(1,length(t)) + (bit_stream(ii)==1)*ones(1,length(t))];
  43.    
  44.     % The ASK Signal
  45.     ASK_signal = [ASK_signal (bit_stream(ii)==0)*A1*sin(2*pi*f*t) + (bit_stream(ii)==1)*A2*sin(2*pi*f*t)];
  46.    
  47.     time = [time t];
  48.     t =  t + 2e-4;
  49. end
  50.  
  51. % Plot the Original Digital Signal
  52. subplot(3,1,1);
  53. plot(time,Digital_signal,'r','LineWidth',2);
  54. xlabel('Time (bit period)');
  55. ylabel('Amplitude');
  56. title('Original Digital Signal');
  57. axis tight;
  58. grid on;
  59.  
  60. % Plot the ASK Signal
  61. subplot(3,1,2);
  62. plot(time,ASK_signal,'LineWidth',1);
  63. xlabel('Time (bit period)');
  64. ylabel('Amplitude');
  65. title('ASK Signal with two Amplitudes');
  66. axis tight;
  67. grid  on;
  68.  
  69. % Plot the ASK Spectrum
  70. Nsamps = length(ASK_signal);
  71. %t1 = (1/fs)*(1:Nsamps);       %Prepare time data for plot
  72.  
  73. %Do Fourier Transform
  74. y_fft = abs(fft(ASK_signal));  %Retain Magnitude
  75. y_fft = y_fft(1:Nsamps/2);     %Discard Half of Points
  76. f1 = fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot
  77.  
  78. %Plot ASK in Frequency Domain
  79. subplot(3,1,3);
  80. plot(f1, y_fft, 'linewidth', 2, 'r');
  81. xlim([0 20e3]);
  82. xlabel('Frequency (Hz)');
  83. ylabel('Amplitude');
  84. title('Spectrum plot for ASK modulated Signal');
  85. grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement