Advertisement
Ostu

Untitled

May 26th, 2021
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.01 KB | None | 0 0
  1. %% Widmo sygnału przed odfiltrowaniem
  2. Y= fft(y);
  3. L=length(y);
  4. P2 = abs(Y/L);
  5. P1 = P2(1:L/2+1);
  6. P1(2:end-1) = 2*P1(2:end-1);
  7. f = fs*(0:(L/2))/L;
  8. figure(1)
  9. plot(f,P1)
  10. xlabel('f (Hz)')
  11. ylabel('|P1(f)|')
  12. ylim([0 0.35])
  13. title("Widmo częstotliwościowe sygnału z pliku")
  14. %% Przebieg sygnału
  15. t=0:1:numel(y)-1;
  16. figure(2)
  17. plot(t,y)
  18. title("Przebieg sygnału przed odfiltrowaniem")
  19. xlim([0 146225])
  20. %% Filtr tłumiący do 170Hz
  21. Wpc=170/(0.5*fs);
  22. Wsc=140/(0.5*fs);
  23. Rpc=3;
  24. Rsc=40;
  25. [nc,Wnc] = cheb1ord(Wpc,Wsc,Rpc,Rsc)
  26. [bc,ac] = cheby1(nc,Rpc,Wnc,'high')
  27. Gc=tf(bc,ac,1/fs)
  28. options = bodeoptions;
  29. options.FreqUnits = 'Hz';
  30. options.FreqScale = 'linear'
  31. figure(3)
  32. bode(Gc, options)
  33. xlim([0 4700])
  34. %% Pierwsze zakłócenie
  35. Wpc21=[605 615]/(0.5*fs)
  36. Wsc21=[595 625]/(0.5*fs)
  37. Rpc21=3;
  38. Rsc21=45;
  39. [nc21,Wnc21]=cheb2ord(Wpc21,Wsc21,Rpc21,Rsc21)
  40. [bc21,ac21]=cheby2(nc21,Rsc21,Wnc21,'stop')
  41. GC21=tf(bc21,ac21,1/fs)
  42. figure(4)
  43. options = bodeoptions;
  44. options.FreqUnits = 'Hz';
  45. options.FreqScale = 'linear'
  46. bode(GC21, options)
  47. xlim([400 800])
  48. %% Drugie zakłócenie
  49. Wpc22=[2475 2490]/(0.5*fs)
  50. Wsc22=[2470 2495]/(0.5*fs)
  51. Rpc22=3;
  52. Rsc22=45;
  53. [nc22,Wnc22]=cheb2ord(Wpc22,Wsc22,Rpc22,Rsc22)
  54. [bc22,ac22]=cheby2(nc22,Rsc22,Wnc22,'stop')
  55. GC22=tf(bc22,ac22,1/fs)
  56. figure(5)
  57. options = bodeoptions;
  58. options.FreqUnits = 'Hz';
  59. options.FreqScale = 'linear'
  60. bode(GC22, options)
  61. xlim([2400 2600])
  62. %% Przepuszczenie sygnału przez filtry
  63. sygfilter1=filter(bc,ac,y);
  64. sygfilter2=filter(bc21,ac21,sygfilter1);
  65. sygfilter3=filter(bc22,ac22,sygfilter2);
  66. %% Widmo sygnału po dofiltrowaniu zakłóceń
  67. Y= fft(sygfilter3);
  68. L=length(sygfilter3);
  69. fs=9000;
  70. P2 = abs(Y/L);
  71. P1 = P2(1:L/2+1);
  72. P1(2:end-1) = 2*P1(2:end-1);
  73. f = fs*(0:(L/2))/L;
  74. figure(6)
  75. plot(f,P1)
  76. xlabel('f (Hz)')
  77. ylabel('|P1(f)|')
  78. title("Widmo częstotliwościowe sygnału po odfiltrowaniu")
  79. %% Odfiltrowany sygnał
  80. t=0:1:numel(y)-1;
  81. figure(7)
  82. plot(t,sygfilter3)
  83. title("Przebieg zadanego sygnału po odfiltrowaniu")
  84. %% Odtworzenie sygnału
  85. sound(sygfilter3,fs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement