References http://www.math.psu.edu/wysocki/M412/Notes412_8.pdf https://zhuanlan.zhihu.com/p/19763358 https://www.math.psu.edu/tseng/class/Math251/Notes-PDE%20pt2.pdf http://www.oulu.fi/sites/default/files/content/files/series.pdf http://www.engr.uconn.edu/~lanbo/G377FFTYC.pdf Fourier Series Theorem (references: Second Order Linear Partial Differential Equations, 复数形式傅立叶变换的物理意义，相位究竟指的是什么？) \(\text{Suppose } f(x) \text{ is a periodic function with period } T \text{ and is an integrable function on } [0, T]. \\ \text{Then, the Fourier Series of } f(x) \text{ can be written as }\) \[ \begin{align} f(x) & = \frac{c_0}{2} + \sum_{n=1}^{\infty} c_ncos(n \cdot \frac{2\pi}{T} \cdot x + \varphi_n) \\ &= \frac{c_0}{2} + \sum_{n=1}^{\infty} c_ncos(\varphi _n)cos(n \cdot \frac{2\pi}{T} \cdot x)+ (-c_n)sin(\varphi _n)sin(n \cdot \frac{2\pi}{T} \cdot x) \\ &\text{( let } a_0 = c_0, \;a_n = c_ncos(\varphi _n) \text{ and } b_n = (-c_n)sin(\varphi _n) \;) \\ &= \frac{a_0}{2} + \sum_{n=1}^{\infty} a_ncos(n \cdot \frac{2\pi}{T} \cdot x)+ b_nsin(n \cdot \frac{2\pi}{T} \cdot x) \\ \\ \text{where } c_n &= \sqrt{a_n^2 + b_n^2} = \sqrt{c_n^2(cos^2(\varphi _n) + sin^2(\varphi _n))} = \sqrt{c_n^2} \;\; (Amplitude)\\ \varphi_n &= tan^{-1}(-\frac{b_n}{a_n}) \;\; (Phase)\\ a_0 &= \frac{1}{T}\int_{0}^{T}f(x)dx \\ a_n &= \frac{1}{T}\int_{0}^{T}f(x) \cdot cos(n \cdot \frac{2\pi}{T} \cdot x)dx \\ b_n &= \frac{1}{T}\int_{0}^{T}f(x) \cdot sin(n \cdot \frac{2\pi}{T} \cdot x)dx \end{align} \]

Read More## Parallel Computing in R

In my work, I usually deal with dataset of products from different customers across different market places. Basically, each product has its own time series dataset. The size of each dataset is not big but we have millions of them. Before finding any convincing reasons to combine dataset from different products, now we just treat them all as independent dataset. And, since they are all independent, it is definitely a good idea to use parallel computing to push the limit of our machine and to make code executed efficiently.

Read More## Connect SQL Server Database to R

When I am working on my personal projects, all the data I have can be easily saved as .csv or .txt files. Things are not complicated. However, when things are in scale, it is hard to not to talk about database. In my company, all the data are stored in SQL Server database. So, it is important for me to know how to connect R with SQL Server. And, also good to know how to interact with database in R by passing variables in R environment to database and then return the desired dataset.

Read More