Narayan

FM_Mod

Jan 21st, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.28 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. m = input('Enter Modulation Index = ');
  10.  
  11. t = [0:1/(100*fC):10/fM]; %10000 samples
  12.  
  13. msg = vm*cos(2*pi*fM*t);
  14. subplot(4,1,1);
  15. plot(t,msg); %plotting message signal
  16. refresh;
  17. xlabel('Time [s]');
  18. ylabel('Amplitude [V]');
  19. title('Message Signal waveform');
  20. grid on;
  21. axis tight
  22.  
  23. carrier = vc*sin(2*pi*fC*t);
  24. subplot(4,1,2);
  25. plot(t,carrier); %plotting carrier signal
  26. xlabel('Time [s]');
  27. ylabel('Amplitude [V]');
  28. title('Carrier Signal waveform');
  29. grid on;
  30. axis tight
  31.  
  32. y = vc*cos(2*pi*fC*t+m*sin(2*pi*fM*t));
  33.  
  34. subplot(4,1,3);
  35. plot(t,y); %plotting FM (Frequency Modulated) signal
  36. xlabel('Time [s]');
  37. ylabel('Amplitude [V]');
  38. title('FM Signal waveform');
  39. grid on;
  40. axis tight
  41.  
  42.  
  43. N = length(y);
  44. fs = 100*fC; %50 mega samples per second
  45. fnyquist = fs/2; %Nyquist frequency
  46. X_mags = abs(fftshift(fft(y)));
  47. bin_vals = [0 : N-1];
  48. N_2 = ceil(N/2);
  49. fax_Hz = (bin_vals-N_2)*fs/N;
  50. subplot (4,1,4);
  51. plot(fax_Hz(N_2:52000), X_mags(N_2:52000), '-r', 'LineWidth', 2 )
  52. xlabel('Frequency [Hz]')
  53. ylabel('Magnitude');
  54. title('Double-sided Magnitude spectrum (Hertz)');
  55. grid on
  56. axis tight
Add Comment
Please, Sign In to add comment