"The Discrete Fourier Transform (DFT) can be used for some very basic signal processing operations. We can either use is for decimation, which results in redcution of the number of samples of a given time series or we can use it for interpolation, which is the opposite of decimation.\n",
"Decimation implies a reduction of time resolution and thus a decrease in the Nyquist frequency.\n",
"If the original signal contains higher frequency than the new Nyquist frequency\n",
"(after decimation) we get aliasing. Thus, a low pass filtering to the new Nyquist\n",
"frequency is required before decimation. Decimation and low-pass filtering can be\n",
"achieved in one step by using the DFT:\n",
"1. Transform the time series to the frequency domain using the DFT.\n",
"2. Reduce the Nyquist frequency by the desired factor (when using the Fast Fourier Transform, this should be a power of 2), and apply an appropriate taper. That’s the low-pass filter!\n",
"3. Do an inverse DFT of the modified spectrum with reduced Nyquist frequency and obtain a time series with greater sampling interval (because lower Nyquist frequency implies lower time resolution)."
"plt.plot(t_data, data - np.mean(data), alpha=0.5)\n",
"plt.plot(t_dec, dec - np.mean(dec), alpha=0.5)\n",
"plt.xlabel(\"Time (s)\")\n",
"plt.ylabel(\"Amplitude (a.u.)\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Interpolation\n",
"The opposite of decimation is interpolation. Here, we want a finer sampling of the\n",
"time series without changing the frequency content. We could do this in the time\n",
"domain by some interpolation rule using neighbouring samples. We can also do it\n",
"by using the DFT:\n",
"1. Transform the time series to the frequency domain using the DFT.\n",
"2. Append zeros to the spectrum thus increasing the Nyquist frequency.\n",
"3. Do an inverse DFT of the extended spectrum and obtain a time series with smaller sampling interval (because higher Nyquist frequency implies higher time resolution). The frequency content is unchanged!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def interpolation(x, dt, new_dt):\n",
" \"\"\"\n",
" Easy function for interpolation of a given data array to increase the the sampling rate.\n",
" \n",
" x: data array\n",
" dt: sampling rate\n",
" new_dt: new sampling rae\n",
" \"\"\"\n",
" # 1. Transform x to frequnecy domain\n",
" ft = np.fft.rfft(x)\n",
" \n",
" # Determine the number of zeros to add\n",
" \n",
" \n",
" # 2. Append zeros to spectrum\n",
" ft = np.concatenate((ft, np.zeros(append_zeros)))\n",