Matt23

cw3z2

Nov 20th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.39 KB | None | 0 0
  1. N = 1024;
  2. f1 = 500;
  3. f2 = 1200;
  4. fs = 8000;
  5. n = 0 : N - 1;
  6.  
  7.  
  8. noise = normrnd(0, sqrt(1), 1, N);
  9. subplot(3, 1, 1);
  10. plot(noise)
  11. axis([0 (N + 10) -4 4])
  12. title('Szum gaussowski');
  13. xlabel('Czas');
  14. ylabel('Amplituda');
  15.  
  16. sin1 = 0.5 * sin(2 * pi * n * f1 / fs);
  17. sin2 = sin(2 * pi * n * f2 / fs);
  18. sumSin = sin1 + sin2;
  19. subplot(3, 1, 2);
  20. plot(sumSin)
  21. axis([0 (N + 10) -2 2])
  22. title('Kombinacja sygnałów sinusoidalnych');
  23. xlabel('Czas');
  24. ylabel('Amplituda');
  25.  
  26. y = sumSin + 0.1 * noise;
  27. subplot(3, 1, 3);
  28. plot(y);
  29. axis([0 (N + 10) -2 2])
  30. title('Suma sygnałów sinusiodalnych i szumu');
  31. xlabel('Czas');
  32. ylabel('Amplituda');
  33.  
  34. % ---------------------------------------------------
  35.  
  36. figure;
  37. subplot(3, 1, 1);
  38. periodogram(noise);
  39.  
  40. subplot(3, 1, 2);
  41. periodogram(sumSin);
  42.  
  43. subplot(3, 1, 3);
  44. periodogram(y);
  45.  
  46. % ---------------------------------------------------
  47.  
  48. figure;
  49. subplot(3, 1, 1);
  50. periodogram(noise, hann(N));
  51.  
  52. subplot(3, 1, 2);
  53. periodogram(sumSin, hann(N));
  54.  
  55. subplot(3, 1, 3);
  56. periodogram(y, hann(N));
  57.  
  58. % ---------------------------------------------------
  59.  
  60. figure;
  61. [pxx1, f1] = pwelch(noise, hann(256), [], N, fs);
  62. [pxx2, f2] = pwelch(noise, hann(128), [], N, fs);
  63. [pxx3, f3] = pwelch(noise, hann(64), [], N, fs);
  64.  
  65. subplot(3, 1, 1);
  66. hold on;
  67. p1 = plot(f1, 10 * log10(pxx1));
  68. p2 = plot(f2, 10 * log10(pxx2));
  69. p3 = plot(f3, 10 * log10(pxx3));
  70.  
  71. xlabel('Frequency (Hz)');
  72. ylabel('PSD dB/Hz');
  73. legend([p1 p2 p3], {'NFFT 256', 'NFFT 128', 'NFFT 64'});
  74. grid on;
  75. hold off;
  76.  
  77. % -------------
  78.  
  79. [pxx1, f1] = pwelch(sumSin, hann(256), [], N, fs);
  80. [pxx2, f2] = pwelch(sumSin, hann(128), [], N, fs);
  81. [pxx3, f3] = pwelch(sumSin, hann(64), [], N, fs);
  82.  
  83. subplot(3, 1, 2);
  84. hold on;
  85. p1 = plot(f1, 10 * log10(pxx1));
  86. p2 = plot(f2, 10 * log10(pxx2));
  87. p3 = plot(f3, 10 * log10(pxx3));
  88.  
  89. axis([-inf inf -160 -10]);
  90. xlabel('Frequency (Hz)');
  91. ylabel('PSD dB/Hz');
  92. legend([p1 p2 p3], {'NFFT 256', 'NFFT 128', 'NFFT 64'});
  93. grid on;
  94. hold off;
  95.  
  96. % -------------
  97.  
  98. [pxx1, f1] = pwelch(y, hann(256), [], N, fs);
  99. [pxx2, f2] = pwelch(y, hann(128), [], N, fs);
  100. [pxx3, f3] = pwelch(y, hann(64), [], N, fs);
  101.  
  102. subplot(3, 1, 3);
  103. hold on;
  104. p1 = plot(f1, 10 * log10(pxx1));
  105. p2 = plot(f2, 10 * log10(pxx2));
  106. p3 = plot(f3, 10 * log10(pxx3));
  107.  
  108. axis([-inf inf -65 -15]);
  109. xlabel('Frequency (Hz)');
  110. ylabel('PSD dB/Hz');
  111. legend([p1 p2 p3], {'NFFT 256', 'NFFT 128', 'NFFT 64'});
  112. grid on;
  113. hold off;
Advertisement
Add Comment
Please, Sign In to add comment