Advertisement
Narayan

FSK_Mod

Jan 21st, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.99 KB | None | 0 0
  1. clc
  2. clear all
  3. close all
  4.  
  5. %vm = input('Enter Amplitude (Message) = ');
  6. %vc = input('Enter Amplitude (Carrier) = ');
  7. fM = input('Enter Message frequency = ');
  8. fC = input('Enter Carrier frequency = ');
  9. deviation = input('Enter Freq. deviation = ');
  10.  
  11. % The number of bits to send - Frame Length
  12. N = 8;
  13.  
  14. % Generate the bit stream
  15. str = input ("Give me some text: ", "s");
  16. message = (dec2bin (uint8 (str), N) - "0").'(:).';
  17. disp (message);
  18.  
  19. %fC = 100e3;
  20. %fM = 10e3;
  21. %deviation = 40e3;
  22. fs = 100 * fC;
  23.  
  24. t = [0 : 1/fs : length(message) * 1/fM];
  25. % t is too large because the endpoint is included.fs
  26. % ugly fix to address this
  27. t = t(1:end-1);
  28.  
  29. % Those are prototype-waveforms for a low and a high bit.
  30. t_prototype    = t(1:end/length(message));
  31. low_prototype  = sin(2*pi*(fC-deviation)*t_prototype);
  32. high_prototype = sin(2*pi*(fC+deviation)*t_prototype);
  33.  
  34. % Piece together protoypes to modulated message
  35. y = [];
  36. for i = message
  37.     if i == 0
  38.         y = [y low_prototype];
  39.     else
  40.         y = [y high_prototype];
  41.     endif;
  42. end
  43.  
  44. upsampling_factor = fs/fM ;
  45. message_resampled = repmat(message, upsampling_factor, 1)(:)' - 0.5;
  46.  
  47. subplot(4,1,1);
  48. plot(t, message_resampled, 'linewidth', 1.5, '-r');
  49. refresh;
  50. xlabel('Time [s]');
  51. ylabel('Amplitude [V]');
  52. title('Message Signal waveform');
  53. grid on;
  54. axis tight;
  55.  
  56. carrier = sin(2*pi*fC*t);
  57. subplot(4,1,2);
  58. plot(t,carrier);
  59. xlabel('Time [s]');
  60. ylabel('Amplitude [V]');
  61. title('Carrier Signal waveform');
  62. grid on;
  63. axis tight;
  64.  
  65. subplot(4,1,3);
  66. plot(t,y);
  67. xlabel('Time [s]');
  68. ylabel('Amplitude [V]');
  69. title('FM Signal waveform');
  70. grid on;
  71. axis tight;
  72.  
  73. Nsamps = length (y);
  74. y_fft = abs (fft (y));            %Retain Magnitude
  75. y_fft = y_fft(1:Nsamps/2);        %Discard Half of Points
  76. f_fft = fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot
  77. subplot (4,1,4);
  78. plot(f_fft, y_fft, 'linewidth', 1.5, '-g');
  79. xlim ([0 2e5]);
  80. ylabel ('Amplitude');
  81. xlabel ('Frequency (Hz)');
  82. title ('Spectrum plot of the FSK modulated signal');
  83. grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement