; docformat = 'rst' ; ; NAME: ; fourierSerie ; PURPOSE: ; Compute the Fourier serie of independant variable x with coefficients A and B ; ;+ ; :Description: ; Compute the Fourier serie of independant variable x with coefficients A and B ; ; :Categories: ; Maths, Evaluation ; ; :Params: ; X: in, required, type=float ; Array (any dimension) of x values. ; P: in, required, type=float ; Period to be used in Fourier expansion ; A: in, required, type=float ; Coefficients of sine in Fourier expansion ; B: in, required, type=float ; Coefficients of cosine in Fourier expansion ; ; :Keywords: ; N: in, optional, type=float ; Coefficients of cosine in Fourier expansion ; x0: in, optional, type=float, default=0 ; Starting time ; ; :Returns: The evaluated Fourier series at positions X ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Original Version written in July 2017, B. Carry (OCA) ; 2017 Aug. - B. Carry (OCA) - Added starting time x0 ;- function fourierSerie, x, P, A, B, N=N, x0=x0 COMPILE_OPT hidden, idl2 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--I.1-- Check Syntax ------------------------------------------------------------------------; if n_params() lt 4 then begin message, 'syntax: serie = fourierSerie(x, P, A, B [,N=, x0=])' return, -1 endif ;--I.2-- Number of Orders --------------------------------------------------------------------; nbA = n_elements(A) nbB = n_elements(B) nbMax = min([nbA,nbB]) ;--I.3-- Manual Limitation of Orders ---------------------------------------------------------; if keyword_set(N) then if (N lt nbMax and N ge 0 ) then nbMax=N ;--I.4-- Starting Rotation Phase -------------------------------------------------------------; if not keyword_set(x0) then x0=0 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Compute the Fourier Expansion -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- Output Variable --------------------------------------------------------------------; y=x*0 ;--II.2-- Loop Over Orders & Evaluate Expansion ---------------------------------------------; for kO=0, nbMax-1 do begin locX = 2*!PI*(kO+1)* (x-x0[0]) / P[0] y += A[kO]*sin(locX) + B[kO]*cos(locX) endfor ;--II.3-- Return the Expansion ---------------------------------------------------------------; return, y end