Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. N = 1000;
  2. fs = 400;
  3.  
  4. t = 0:1/fs:(N-1)/fs;
  5.  
  6. f1 = 20;
  7. f2 = 70;
  8. f3 = 150;
  9.  
  10. A1 = 2;
  11. A2 = 1;
  12. A3 = 4;
  13.  
  14. phi1 = 0;
  15. phi2 = pi/4;
  16. phi3 = pi/6;
  17.  
  18. n = randn(1,1000);
  19.  
  20. x1 = A1*sin(2*pi*f1*t + phi1);
  21. x2 = A2*sin(2*pi*f2*t + phi2);
  22. x3 = A3*sin(2*pi*f3*t + phi3);
  23.  
  24. x = x1+x2+x3;
  25.  
  26. SNR = max(x)/5;
  27.  
  28. noise = mod(n,SNR);
  29.  
  30. subplot(3,1,1), plot(t,x+noise);
  31. xlabel('czas [t]');
  32. ylabel('x(t)')
  33.  
  34. y = fft(x);
  35. m = 20*log10(abs(y));
  36. p = unwrap(angle(y));
  37.  
  38. f = 0:fs/N:fs - fs/N;
  39.  
  40. %index = (1:fs);
  41.  
  42. subplot(3,1,2), plot(f,m); %wykres amplitudy
  43. ylabel('modul amplitudy'), grid on
  44. subplot(3,1,3), plot(f,p*180*pi); %faza
  45. ylabel('faza [stopnie]'), grid on
  46. xlabel('Czestotliwosc [Hz]')
  47.  
  48. clear all;
  49. clc;
  50.  
  51. %********************************************************************
  52.  
  53. N = 300;
  54. fs = 1500;
  55.  
  56. t = 0:1/fs:(N-1)/fs;
  57.  
  58. f1 = 120;
  59. f2 = 127;
  60. f3 = 250;
  61.  
  62. A1 = 2;
  63. A2 = 1;
  64. A3 = 4;
  65.  
  66. phi1 = 0;
  67. phi2 = pi/4;
  68. phi3 = pi/6;
  69.  
  70. n = randn(1,N);
  71.  
  72. x1 = A1*sin(2*pi*f1*t + phi1);
  73. x2 = A2*sin(2*pi*f2*t + phi2);
  74. x3 = A3*sin(2*pi*f3*t + phi3);
  75.  
  76. x = x1+x2+x3;
  77.  
  78. SNR = x.^2/(35*20*log10(abs(n)));
  79.  
  80. noise = mod(n,SNR);
  81.  
  82. subplot(3,1,1), plot(t,x+noise);
  83. xlabel('czas [t]');
  84. ylabel('x(t)')
  85.  
  86. y = fft(x);
  87. m = 20*log10(abs(y));
  88. p = unwrap(angle(y));
  89.  
  90. f = 0:fs/N:fs - fs/N;
  91.  
  92. %index = (1:fs);
  93.  
  94. subplot(3,1,2), plot(f,m); %wykres amplitudy
  95. ylabel('modul amplitudy'), grid on
  96. subplot(3,1,3), plot(f,p*180*pi); %faza
  97. ylabel('faza [stopnie]'), grid on
  98. xlabel('Czestotliwosc [Hz]');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement