Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.09 KB | None | 0 0
  1. clc, close all, clear all
  2. %%Zadanie 1
  3.  
  4. %Data
  5. fs = 5000; %Sample freq
  6. fm = 1; %1
  7. fc = 100; %Carrier freq
  8. Am = 1;
  9. Ac = 0.5;
  10. kf = 20;
  11. b = (kf*Ac)/fm;
  12. t = 0:1/fs:((4/fm)-(1/fs));
  13.  
  14. %Modulated signal
  15. msignal = Am*cos(2*pi*fm*t);
  16. c_msignal = cumsum(msignal)/fs;
  17.  
  18. msignal2 = square(2*pi*fm*t)*(1.5/2)+0.15;
  19. c_msignal2 = cumsum(msignal2)/fs;
  20.  
  21. xfm = cos(2*pi*fc*t).*cos(2*pi*b*c_msignal)-sin(2*pi*fc*t).*sin(2*pi*b*c_msignal);
  22. xfm2 = cos(2*pi*fc*t).*cos(2*pi*b*c_msignal2)-sin(2*pi*fc*t).*sin(2*pi*b*c_msignal2);
  23. xfm_func = fmmod(msignal,fc,fs,b);
  24. xfm_func2 = fmmod(msignal2,fc,fs,b);
  25.  
  26. %Spectres
  27. NoOfProbes = 2^nextpow2( length(xfm) );
  28. xfm_spec = 20*log10(abs(fft(xfm,NoOfProbes)/NoOfProbes));
  29. xfm_spec2 = 20*log10(abs(fft(xfm2,NoOfProbes)/NoOfProbes));
  30.  
  31. f_w_b=fs/2*linspace(-1,1,NoOfProbes);
  32.  
  33. %Modulation (1st - sin signal)
  34. figure(1)
  35. subplot(4,1,1);
  36. plot(msignal);grid;
  37. title('Message signal');
  38. %xlim([20000 100000]);
  39. subplot(4,1,2);
  40. plot(xfm);grid;
  41. title('Modulated signal');
  42. %xlim([20000 100000]);
  43. subplot(4,1,3);
  44. plot(xfm_func);grid
  45. title('Modulated signal with fmmod function');
  46. %xlim([20000 100000]);
  47. subplot(4,1,4);
  48. plot(f_w_b,[xfm_spec(NoOfProbes/2+2:end), xfm_spec(1:NoOfProbes/2+1)]);grid
  49. title('Spectre of modulated sin signal');
  50. ylabel('FFT [dB]','FontSize',12);
  51.  
  52. %Modulation (2nd - square signal)
  53. figure(2)
  54. subplot(4,1,1);
  55. plot(msignal2);grid;
  56. title('Message signal');
  57. %xlim([20000 100000]);
  58. subplot(4,1,2);
  59. plot(xfm2);grid;
  60. title('Modulated signal');
  61. %xlim([20000 100000]);
  62. subplot(4,1,3);
  63. plot(xfm_func2);grid
  64. title('Modulated signal with fmmod function');
  65. %xlim([20000 100000]);
  66. subplot(4,1,4);
  67. plot(f_w_b,[xfm_spec2(NoOfProbes/2+2:end),xfm_spec2(1:NoOfProbes/2+1)]);grid
  68. title('Spectre of modulated square signal');
  69. xlabel('f [Hz]','FontSize',12);
  70. ylabel('FFT [dB]','FontSize',12);
  71.  
  72. msignalPower = rms(msignal)*rms(msignal)
  73. c_msignalPower = rms(c_msignal)*rms(c_msignal)
  74. xfmPower = rms(xfm)*rms(xfm)
  75. xfm2Power = rms(xfm2)*rms(xfm2)
  76.  
  77. s = hilbert(xfm).*exp(sqrt(-1)*2*pi*fc*t);
  78. figure;
  79. plot(s)
  80. Z = fmdemod(xfm,fc,fs,b);
  81.  
  82. %Waskopasmowa - b musi byc male
  83. %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement