Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. clear;clc;
  2. %% generate x-axe
  3. first_step=0;
  4. step_t=0.01;
  5. last_step=1;
  6. t=first_step:step_t:last_step;
  7. %% signal and fourier transform
  8. y= 2*sin(2*pi*60*t) ;
  9. figure(1)
  10. plot(t,y);title('signal')
  11. fourier=fft(y );
  12. N_=length(fourier);
  13. f_ = (1 / step_t) * ( 0: (N_/2) ) / N_;
  14. a=(fourier.*conj(fourier))/(N_*N_); % Spectral Density get half
  15. a = a(1:N_ /2+1);
  16. a(2:end-1) = 4*a(2:end-1);
  17. figure(2);
  18. plot(f_,a);title('Spectrum Power through signal');
  19. %% through AutoCorrelation function
  20. tau=0.01;
  21. y1= 2*sin(2*pi*60*(t+tau)) ;
  22. Y=y1.*y;
  23. AutoCorr_func = cumtrapz(Y,t);
  24. figure(3);
  25. plot(t,AutoCorr_func); title('AutoCorrelation function');
  26. fourier=fft(AutoCorr_func);
  27. N_=length(fourier);
  28. f_ = (1 / step_t) * ( 0: (N_/2) ) / N_;
  29. a=fourier.*conj(fourier) ; % Spectral Density
  30. a = a(1:N_ /2+1); % spectrum is even, so get half
  31. a(2:end-1) = a(2:end-1); % multiply by 4, since spectrum is square of amplitude, and we have two even halves
  32. figure(4)
  33. plot(f_ ,a );
  34. title('Spectrum through AutoCorrelation funciton');
  35.  
  36. Y=y1.*y;
  37. AutoCorr_func = cumtrapz(Y,t);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement