{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6c616b70",
   "metadata": {},
   "outputs": [],
   "source": [
    "from Analyzer import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "96bd598e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Calculating power spectrum...\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 141176 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"Synthetic data to validate analysis\"\"\"\n",
    "# # Generate time series data with values against time in seconds\n",
    "# num_seconds = 10  # Total number of seconds\n",
    "# time        = np.arange(0, num_seconds, 1/30)  # Create timestamp index\n",
    "# voltage     = np.sin(2*np.pi*4*time) + np.sin(2*np.pi*7*time) + np.random.randn(len(time))*0.2  # Generate 4 Hz and 7 Hz sine wave\n",
    "# data = np.column_stack((time, voltage))\n",
    "\n",
    "\"\"\"Real data\"\"\"    \n",
    "\n",
    "ac_filename_list = [\"20240807/AC Coupling/P1.0_M0_OOL\",\n",
    "                    \"20240807/AC Coupling/P5.0_M1.1_OOL\",\n",
    "                    \"20240807/AC Coupling/P6.0_M2.1_OOL\",\n",
    "                    \"20240807/AC Coupling/P7.0_M3.0_OOL\"]\n",
    "\n",
    "dc_filename_list = [\"20240807/DC Coupling/P1.0_M0_OOL\",\n",
    "                    \"20240807/DC Coupling/P5.0_M1.1_OOL\",\n",
    "                    \"20240807/DC Coupling/P6.0_M2.1_OOL\",\n",
    "                    \"20240807/DC Coupling/P7.0_M3.0_OOL\"]\n",
    "\n",
    "idx = 3\n",
    "\n",
    "filename = ac_filename_list[idx]\n",
    "dir      = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time-Series-Data/\"\n",
    "filepath_data = dir + filename + \".csv\"\n",
    "ac_data = extract_data(filepath_data)\n",
    "\n",
    "filename = dc_filename_list[idx]\n",
    "dir      = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time-Series-Data/\"\n",
    "filepath_data = dir + filename + \".csv\"\n",
    "dc_data = extract_data(filepath_data)\n",
    "\n",
    "# Extract the first and second columns from data_array\n",
    "dc_voltages                   = dc_data[:, 1]\n",
    "ac_time                       = ac_data[:, 0]\n",
    "\n",
    "processed_ac_data, Sxx_smooth = compute_psd(ac_data)\n",
    "\n",
    "dt      = ac_time[1] - ac_time[0]                     # Sampling interval / time step\n",
    "N       = ac_time.shape[0]                            # Total number of data points\n",
    "f_s     = 1 / dt                                      # Sampling frequency\n",
    "delta_f = f_s/N;                                      # Step size in frequency domain\n",
    "\n",
    "Skk, RIN_Sxx_smooth           = compute_RIN(dc_voltages, delta_f, Sxx_smooth)\n",
    "\n",
    "# plot_psd(processed_ac_data, Sxx_smooth, filename.split('/')[-1])\n",
    "\n",
    "plot_rin(processed_ac_data, RIN_Sxx_smooth, filename.split('/')[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1db01efd",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot_e_folding_time(processed_ac_data, Skk, 100, 1000, filename.split('/')[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f19dbfa",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot_e_folding_time(processed_ac_data, Skk, 1000, 5000, filename.split('/')[-1])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
