# Function Testing ## Fitting Data The purpose of using fitting data is to check the correctness of self-defined function of 2D Fourier transform. In this program, the fitting data is designed as a leftward (westly) propagation wave, which is constructed by superposition of wave of different wave number and angular frequency. Basic function of the wave: $$y(x, t) = Acos(kx+\omega t)$$ Range of wave number and angular frequency are both 1 to 100. To examine if the wave has propagated toward west, there is the shaded contour figure: ![](https://hackmd.io/_uploads/rywNv0Oth.png) It is obvious that the wave is propagate toward west (left). So the fitting data is correct. ## Function of 2D Fourier Transform Detailed Coding likes below: ``` def DFT(arr): N = np.shape(arr)[1] n = np.matrix(np.linspace(0, N-1, N)) k = 2 * np.pi * np.matrix(np.linspace(0, N-1, N)) / N C_k = np.cos(+k.T * n) * np.matrix(arr).T / (N) S_k = np.sin(+k.T * n) * np.matrix(arr).T / (N) return C_k, S_k ``` This is the one dimension DFT function. If wanna ask for Fourier transform on the second dimension, the transpose of the wave array is needed. This function separates the consequence of Fourier transform into two parts, it can be derived from Eulerian formula: $$e^{i\theta} = cos(\theta)+isin(\theta)$$ The expression will being two parts: $$\hat{x_c[\xi]} = \frac{2}{N}\Sigma_{n = 0}^{N-1}cos(\frac{2\pi}{N}*n*k)\;x[n]$$ and $$\hat{x_s[\xi]} = \frac{2}{N}\Sigma_{n = 0}^{N-1}sin(\frac{2\pi}{N}*n*k)\;x[n]$$ In the `DFT` function, the `C_k, S_k` represents the two consequences. Therefore, If there are two dimensions to be transformed, there will be four arrays to be output. In the coding file at the bottom of this report, variables `A, B, a, b` represent the four condition of the solutions. # Power Spectrum It is a common-used method to analysis the behavior of wave on $\omega -k$ plane. The purpose of this analysis method is to examine the intensity / power of the wave which is mixed with different wave number and angular frequency. As the former part, there is `A, B, a, b` as the consequences of Fourier transform. By the definition of power spectrum, the expression can be written in: $$\hat{P} = \frac{1}{8}((A^2+B^2+a^2+b^2)\pm 2(aB-bA))$$ But in the consequence showing, only the negative result will be shown, since the all of the element waves in mixing waves are all propagate toward westly. ## Result of Analysis By all the discussion above, there will produce the follow image, showing power spectrum of the mixing wave. ![](https://hackmd.io/_uploads/B1rrD0uF3.png) Since there is a special wave at wave number 3 and frequency 5, there will be a strong signal at this diagram. # Detailed Coding https://colab.research.google.com/drive/1fc2y7X8jYpj66FSUmE_CtcXAjtyZgyMM?usp=sharing ## Additional Diagram Since there are many wave modes propagate toward different direction in the real world, one of the axis should be expanded, which can show the direction that the wave modes transmit. Therefore, based on the method above, an additional wave, with wave number 3 frequency 5 toward east, is added into the whole wave field. The Space-Time diagram looks like below: ![](https://hackmd.io/_uploads/rJCEoyttn.png) Since the wave number and frequency of the strong wave is fixed, then the $\omega$-k diagram can be expected to have two points, (-3, 5) and (3, 5), to have peak value. The diagram looks like below: ![](https://hackmd.io/_uploads/r1PTj1FFh.png)