Advertisement
Guest User

Untitled

a guest
May 20th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.47 KB | None | 0 0
  1. function [a0,A,B] = fourier(l,n,f) //wszystko bezposrednio z wzorow ( http://www.dspguide.com/graphics/E_13_5.gif ), uzycie ponizej
  2.     a0 = 1/l*intg(-l,l,f,1e-2)
  3.     for i=1:n
  4.         function b=f1(x)
  5.             b = f(x)*cos(i*%pi*x/l)
  6.         endfunction
  7.         function c=f2(x)
  8.             c = f(x)*sin(i*%pi*x/l)
  9.         endfunction
  10.         A(i) = 1/l*intg(-l,l,f1,1e-2)
  11.         B(i) = 1/l*intg(-l,l,f2,1e-2)
  12.     end
  13. endfunction
  14.  
  15. function result = prostokatna(x) //definujemy przykladowa funkcje
  16.     if x-floor(x)<0.5 then
  17.         result = 1
  18.     else
  19.         result = 0
  20.     end
  21. endfunction
  22.  
  23.  
  24. function result = trojkatna(x) //definujemy przykladowa funkcje
  25.     if x - floor(x)<0.5 then
  26.         result = x - floor(x)
  27.     else
  28.         result = 1-x + floor(x)
  29.     end
  30. endfunction
  31.  
  32. function result = piloksztaltna(x) //definujemy przykladowa funkcje
  33.     result = x - floor(x)
  34. endfunction
  35.  
  36. f = prostokatna //wybor funkcji
  37.  
  38. l = 0.5 //polowa okresu funkcji
  39. t = 0:0.02:3
  40.  
  41. N = 2 //do ilu wspolczynnikow rozwijamy, więcej -> dokladniejsze odwzorowanie pierwotnej funkcji
  42.  
  43. [a0,A,B] = fourier(l,N,f)
  44. subplot(311)
  45. plot(t,B'*sin([1:N]'*t*%pi/l)+A'*cos([1:N]'*t*%pi/l)+a0/2,t,f) //przemnazanie i sumowanie skladowych w jednej linijce
  46.  
  47. N = 6
  48.  
  49. [a0,A,B] = fourier(l,N,f)
  50. subplot(312)
  51. plot(t,B'*sin([1:N]'*t*%pi/l)+A'*cos([1:N]'*t*%pi/l)+a0/2,t,f)
  52.  
  53. N = 10
  54.  
  55. [a0,A,B] = fourier(l,N,f)
  56. subplot(313)
  57. plot(t,B'*sin([1:N]'*t*%pi/l)+A'*cos([1:N]'*t*%pi/l)+a0/2,t,f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement