Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 4.88 KB | None | 0 0
  1. function [ ] = zad4()
  2. fs = 8000;
  3.  
  4. b = oblicz_b(fs, 1000);
  5. [h1, t1] = freqz(b, oblicz_a(0, fs, 1000));
  6. [h2, t2] = freqz(b, oblicz_a(0.5, fs, 1000));
  7. [h3, t3] = freqz(b, oblicz_a(0.9, fs, 1000));
  8. [h4, t4] = freqz(b, oblicz_a(1, fs, 1000));
  9. [h5, t5] = freqz(b, oblicz_a(1.1, fs, 1000));
  10. [h6, t6] = freqz(b, oblicz_a(2, fs, 1000));
  11. [h7, t7] = freqz(b, oblicz_a(3, fs, 1000));
  12.  
  13. figure();
  14. plot(oblicz_t(t1, fs), oblicz_mag(h1), oblicz_t(t2, fs), oblicz_mag(h2), oblicz_t(t3, fs), oblicz_mag(h3), oblicz_t(t4, fs), oblicz_mag(h4), oblicz_t(t5, fs), oblicz_mag(h5), oblicz_t(t6, fs), oblicz_mag(h6), oblicz_t(t7, fs), oblicz_mag(h7));
  15. title('Charakterystyka amplitudowa, f0 = 1000 Hz');
  16. ylabel('Amplituda [dB]');
  17. xlabel('Częstotliwość [Hz]');
  18. ylim([-75 15]);
  19. legend('r = 0', 'r = 0.5', 'r = 0.9', 'r = 1', 'r = 1.1', 'r = 2', 'r = 3');
  20. grid on;
  21.  
  22.  
  23. b = oblicz_b(fs, 2000);
  24. [h1, t1] = freqz(b, oblicz_a(0, fs, 2000));
  25. [h2, t2] = freqz(b, oblicz_a(0.5, fs, 2000));
  26. [h3, t3] = freqz(b, oblicz_a(0.9, fs, 2000));
  27. [h4, t4] = freqz(b, oblicz_a(1, fs, 2000));
  28. [h5, t5] = freqz(b, oblicz_a(1.1, fs, 2000));
  29. [h6, t6] = freqz(b, oblicz_a(2, fs, 2000));
  30. [h7, t7] = freqz(b, oblicz_a(3, fs, 2000));
  31.  
  32. figure();
  33. plot(oblicz_t(t1, fs), oblicz_mag(h1), oblicz_t(t2, fs), oblicz_mag(h2), oblicz_t(t3, fs), oblicz_mag(h3), oblicz_t(t4, fs), oblicz_mag(h4), oblicz_t(t5, fs), oblicz_mag(h5), oblicz_t(t6, fs), oblicz_mag(h6), oblicz_t(t7, fs), oblicz_mag(h7));
  34. title('Charakterystyka amplitudowa, f0 = 2000 Hz');
  35. ylabel('Amplituda [dB]');
  36. xlabel('Częstotliwość [Hz]');
  37. ylim([-75 15]);
  38. legend('r = 0', 'r = 0.5', 'r = 0.9', 'r = 1', 'r = 1.1', 'r = 2', 'r = 3');
  39. grid on;
  40.  
  41.  
  42. b = oblicz_b(fs, 3000);
  43. [h1, t1] = freqz(b, oblicz_a(0, fs, 3000));
  44. [h2, t2] = freqz(b, oblicz_a(0.5, fs, 3000));
  45. [h3, t3] = freqz(b, oblicz_a(0.9, fs, 3000));
  46. [h4, t4] = freqz(b, oblicz_a(1, fs, 3000));
  47. [h5, t5] = freqz(b, oblicz_a(1.1, fs, 3000));
  48. [h6, t6] = freqz(b, oblicz_a(2, fs, 3000));
  49. [h7, t7] = freqz(b, oblicz_a(3, fs, 3000));
  50.  
  51. figure();
  52. plot(oblicz_t(t1, fs), oblicz_mag(h1), oblicz_t(t2, fs), oblicz_mag(h2), oblicz_t(t3, fs), oblicz_mag(h3), oblicz_t(t4, fs), oblicz_mag(h4), oblicz_t(t5, fs), oblicz_mag(h5), oblicz_t(t6, fs), oblicz_mag(h6), oblicz_t(t7, fs), oblicz_mag(h7));
  53. title('Charakterystyka amplitudowa, f0 = 3000 Hz');
  54. xlabel('Częstotliwość [Hz]');
  55. ylabel('Amplituda [dB]');
  56. ylim([-75 15]);
  57. legend('r = 0', 'r = 0.5', 'r = 0.9', 'r = 1', 'r = 1.1', 'r = 2', 'r = 3');
  58. grid on;
  59.  
  60. gauss = normrnd(0, sqrt(0.5), 1, fs);
  61.  
  62. y = filter(oblicz_b(fs, 1000), oblicz_a(0.9, fs, 1000), gauss);
  63. figure();
  64. spectrogram(y, window(@hann, 256), 0, 256, fs, 'yaxis');
  65. title(['Spektrogram filtrowanego szumu, f0 = 1000' ', r = 0.9']);
  66. ylabel(colorbar, 'Moc/częstotliwość [dB/Hz]');
  67. xlabel('Czas [s]');
  68. ylabel('Częstotliwość [Hz]');
  69.  
  70. y = filter(oblicz_b(fs, 2000), oblicz_a(0.9, fs, 2000), gauss);
  71. figure();
  72. spectrogram(y, window(@hann, 256), 0, 256, fs, 'yaxis');
  73. title(['Spektrogram filtrowanego szumu, f0 = 2000' ', r = 0.9']);
  74. ylabel(colorbar, 'Moc/częstotliwość [dB/Hz]');
  75. xlabel('Czas [s]');
  76. ylabel('Częstotliwość [Hz]');
  77.  
  78.  
  79. y = filter(oblicz_b(fs, 3000), oblicz_a(0.9, fs, 3000), gauss);
  80. figure();
  81. spectrogram(y, window(@hann, 256), 0, 256, fs, 'yaxis');
  82. title(['Spektrogram filtrowanego szumu, f0 = 3000' ', r = 0.9']);
  83. ylabel(colorbar, 'Moc/częstotliwość [dB/Hz]');
  84. xlabel('Czas [s]');
  85. ylabel('Częstotliwość [Hz]');
  86.  
  87. y = filter(oblicz_b(fs, 2000), oblicz_a(0, fs, 2000), gauss);
  88. figure();
  89. spectrogram(y, window(@hann, 256), 0, 256, fs, 'yaxis');
  90. title(['Spektrogram filtrowanego szumu, f0 = 2000' ', r = 0']);
  91. ylabel(colorbar, 'Moc/częstotliwość [dB/Hz]');
  92. xlabel('Czas [s]');
  93. ylabel('Częstotliwość [Hz]');
  94.  
  95. y = filter(oblicz_b(fs, 2000), oblicz_a(0.5, fs, 2000), gauss);
  96. figure();
  97. spectrogram(y, window(@hann, 256), 0, 256, fs, 'yaxis');
  98. title(['Spektrogram filtrowanego szumu, f0 = 2000' ', r = 0.5']);
  99. ylabel(colorbar, 'Moc/częstotliwość [dB/Hz]');
  100. xlabel('Czas [s]');
  101. ylabel('Częstotliwość [Hz]');
  102.  
  103. y = filter(oblicz_b(fs, 2000), oblicz_a(1, fs, 2000), gauss);
  104. figure();
  105. spectrogram(y, window(@hann, 256), 0, 256, fs, 'yaxis');
  106. title(['Spektrogram filtrowanego szumu, f0 = 2000' ', r = 1']);
  107. ylabel(colorbar, 'Moc/częstotliwość [dB/Hz]');
  108. xlabel('Czas [s]');
  109. ylabel('Częstotliwość [Hz]');
  110.  
  111. y = filter(oblicz_b(fs, 2000), oblicz_a(1.1, fs, 2000), gauss);
  112. figure();
  113. spectrogram(y, window(@hann, 256), 0, 256, fs, 'yaxis');
  114. title(['Spektrogram filtrowanego szumu, f0 = 2000' ', r = 1.1']);
  115. ylabel(colorbar, 'Moc/częstotliwość [dB/Hz]');
  116. xlabel('Czas [s]');
  117. ylabel('Częstotliwość [Hz]');
  118. end
  119.  
  120. function [ t ] = oblicz_t(t, fs)
  121. t = t*fs/(2*pi);
  122. end
  123. function [ h ] = oblicz_mag(h_in)
  124. h = mag2db(abs(h_in));
  125. end
  126. function [ b ] = oblicz_b(fs, f0)
  127. b = [1, -2*cos(2*pi*f0/fs), 1];
  128. end
  129. function [ a ] = oblicz_a(r, fs, f0)
  130. a = [1, -2*r*cos(2*pi*f0/fs), r*r];
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement