Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. Fs = 1000; % Sampling frequency
  6. T = 1/Fs; % Sampling period
  7. L = 128; % Length of signal
  8. t = (0:L-1)*T; % Time vector
  9. S = sin(2*pi*10*t) + sin(2*pi*20*t) + sin(2*pi*40*t) + sin(2*pi*80*t);
  10. X = S + 2*randn(size(t));
  11. plot(1000*t(1:50),X(1:50))
  12. title('Signal Corrupted with Zero-Mean Random Noise')
  13. xlabel('t (milliseconds)')
  14. ylabel('X(t)')
  15. Y = fft(X);
  16. P2 = abs(Y/L);
  17. P1 = P2(1:L/2+1);
  18. P1(2:end-1) = 2*P1(2:end-1);
  19. f = Fs*(0:(L/2))/L;
  20. plot(f,P1)
  21. title('Single-Sided Amplitude Spectrum of X(t)')
  22. xlabel('f (Hz)')
  23. ylabel('|P1(f)|')
  24. Y = fft(S);
  25. P2 = abs(Y/L);
  26. P1 = P2(1:L/2+1);
  27. P1(2:end-1) = 2*P1(2:end-1);
  28.  
  29. plot(f,P1)
  30. title('Single-Sided Amplitude Spectrum of S(t)')
  31. xlabel('f (Hz)')
  32. ylabel('|P1(f)|')
  33. N = 2048; fpr=100; fx1=10; fx2=20; fx3=40;fx4=80;
  34. nx = 0:N-1; dt = 1/fpr; t = dt*nx;
  35. x1 = cos(2*pi*fx1*t);
  36. x2 = cos(2*pi*fx2*t);
  37. x3 = cos(2*pi*fx3*t);
  38. x4 = cos(2*pi*fx4*t);
  39. x = x1 + x2 + x3 + x4;
  40. M = 7; fg = 20;
  41. h = fir1(M-1,2*fg/fpr);
  42. subplot(311); stem(f,'filled'); grid;
  43. title('Sygnał filtrowany');
  44. subplot(312); stem(Y,'filled'); grid;
  45. title('Odp impulsowa filtru FIR');
  46. subplot(313)
  47. splot = conv(S,h,'same');
  48. plot(splot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement