Advertisement
Guest User

signalfft

a guest
Feb 11th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.84 KB | None | 0 0
  1. Fs = 10000;           % Sampling frequency
  2. T = 1/Fs;             % Sampling period
  3. L = 10000;            % Length of signal
  4. t = (0:L-1)*T;        % Time vector
  5.  
  6. simples = zeros(size(t,2),3);
  7. simples(:,1) = 0.7*sin(2*pi*50*t);
  8. simples(:,2) = sin(2*pi*120*t);
  9. simples(:,3) = 2*sin(2*pi*250*t);
  10.  
  11. S = (simples(:,1) + simples(:,2) + simples(:,3)).';     %Source signal
  12.  
  13. plot(1000*t(1:250),simples(1:250))
  14. title('Source Signal')
  15. xlabel('t (milliseconds)')
  16. ylabel('S(t)')
  17.  
  18. X = S + 2*randn(size(t));       %Source signla + Noise
  19.  
  20. plot(1000*t(1:500),simples(1:500,:))
  21. title('Signal + Noise')
  22. xlabel('t (milliseconds)')
  23. ylabel('X(t)')
  24.  
  25. Y = fft(X);
  26. P2 = abs(Y/L);
  27. P1 = P2(1:L/2+1);
  28. P1(2:end-1) = 2*P1(2:end-1);
  29.  
  30. f = Fs*(0:(L/2))/L;
  31. plot(f(1:500),P1(1:500))
  32. title('Single-Sided Amplitude Spectrum of X(t)')
  33. xlabel('f (Hz)')
  34. ylabel('|P1(f)|')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement