| > | restart; |
# Derive the Fourier Sine/Cosine Series Representation of periodic signal, express up to 9th harmonics.
# f(t) = 5 ( u(t+2) - u(t-2) ), period of 8.

| > | fourierREPT:= #func ---------------- any given function, eg. t^2-6*t+2 #trange:name=range --- range of indept var, eg. t=0..10 #m:posint ------------ positive integer (>0), eg. 6 proc( func, trange:: name=range, m:: posint ) local t,A,B,T,n,j,p,q,partsum; A:=lhs(rhs(trange)); B:=rhs(rhs(trange)); T:=B-A; t:=2*Pi*lhs(trange)/T; partsum:=1/T*evalf(int( func,trange)); for n from 1 to m do partsum:=partsum +2/T*evalf(int(func*sin(n*t),trange))*sin(n*t) +2/T*evalf(int(func*cos(n*t),trange))*cos(n*t); od; end: # =================================== with(plots): alias(u=Heaviside): f:=5*(u(t+2)-u(t-2)); g:=fourierREPT(f,t=-4..4,9); plot({f,g},t=-4..4,title='f_and_g'); |
Warning, the name changecoords has been redefined
| > |