Guest User

Untitled

a guest
Jun 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. close all; clear all;
  2. N=1024; sigma = linspace(-pi,pi,N); y= sin(sigma);
  3.  
  4. h=sum(y)/N;
  5. y = y-h;
  6.  
  7. cn = 2/N *fft(y); % FFT to retriece the complex Fourier coeff
  8. cn= cn(1:N/2); % taking half of the coeff because FFT is symmetric
  9.  
  10. bk = real(cn); ak = imag(cn); % fourier coefficient
  11.  
  12. %%% calculation of the initial function approximate by FFT
  13. for i=1:N
  14. yf(i) = 0; % initialisation
  15. for j=1:length(ak)
  16. jj=j-1;
  17. yf(i) = (yf(i) +( ak(j)*sin(jj*sigma(i) )+ bk(j)*cos(jj*sigma(i)) ));
  18. end
  19. end
  20.  
  21. %%% calculation of the first and second derivative in therms of sigma
  22.  
  23. for j = 1:N
  24. Yo(j) = 0;
  25. Yoo(j) = 0;
  26.  
  27. for l=2:length(ak)
  28. k=l-1;
  29. kk=k;
  30. Yo(j) = (Yo(j) + kk*( ak(l) * cos(k*sigma(j)) - bk(l) * sin(k*sigma(j)) ) );
  31. Yoo(j) = (Yoo(j) - kk^2 *( ak(l) * sin(k*sigma(j)) + bk(l) * cos(k*sigma(j)) ) );
  32. end
  33. end
  34.  
  35.  
  36. plot(sigma,yf); hold on
  37. plot(sigma,Yo)
  38. xlabel('sigma'); ylabel('y')
  39. hold off
Add Comment
Please, Sign In to add comment