Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.35 KB | None | 0 0
  1. % function y = filter_zad1(x)
  2. %   b0 = 1;
  3. %   b1 = 0;
  4. %   b2 = 0;
  5. %   a1 = 1;
  6. %   a2 = 0;
  7. %   y(1) = b0*x(1);
  8. %   y(2) = b0*x(2) + b1*x(1) - a1*y(1);
  9. %   for n = 3: length(x)
  10. %       y(n) = b0*x(n) + b1*x(n-1) + b2*x(n-2) - a1*y(n-1) - a2*y(n-2);
  11. %   end
  12. % end
  13.  
  14. N = 64;
  15. X = linspace(0, N-1, N);
  16. imp = double(kroneckerDelta(sym(X)))';
  17.  
  18. b = [1 0 0]
  19. a = [1 1 0]
  20.  
  21. filteredImp = filter_zad1(imp)';
  22. stdFilteredImp = filter(b, a, imp);
  23.  
  24. s = stem(filteredImp);
  25. title('Przetworzony sygnał impulsowy przez napisaną przez na funkcję');
  26. xlabel('Nr próbki'); ylabel('Ampituda');
  27.  
  28. figure;
  29. s = stem(stdFilteredImp);
  30. title('Przetworzony sygnał impulsowy przez funkcję wbudowaną filter');
  31. xlabel('Nr próbki'); ylabel('Ampituda');
  32.  
  33.  
  34. [h, w] = freqz(filteredImp);
  35.  
  36. figure;
  37. plot(w/pi, 20*log10(abs(h)))
  38.  
  39. [phi, w] = phasez(filteredImp);
  40. figure;
  41. plot(w/pi, phi*180/pi);
  42.  
  43. figure;
  44. plotyy(w/pi, 20*log10(abs(h)), w/pi, phi*180/pi);
  45.  
  46.  
  47. fvtool(b, a,'polezero');
  48. [bx,ax] = eqtflength(bf,af);
  49. [z,p,k] = tf2zp(bx,ax);
  50. text(real(z)+.1, imag(z), 'zero');
  51. text(real(p)+.1, imag(p), 'biegun');  
  52.  
  53. noise = wgn(N, 1, 0);
  54.  
  55. figure;
  56.  
  57. filteredNoise = filter(b, a, noise);
  58. stem([noise, filteredNoise]);
  59.  
  60. figure;
  61. spec = abs(fft(noise));
  62. stem(spec);
  63.  
  64.  
  65. figure;
  66. filteredSpec = abs(fft(filteredNoise));
  67. stem(filteredSpec);
  68.  
  69. figure;
  70. stem([spec filteredSpec]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement