Calculations/Time Series Analyzer/TimeSeriesAnalysis.ipynb

553 lines
953 KiB
Plaintext
Raw Normal View History

2024-03-25 17:52:11 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "6c616b70",
"metadata": {},
"outputs": [],
"source": [
"from TimeSeriesAnalyzer import *\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import os\n",
"from scipy import signal"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "96bd598e",
"metadata": {},
"outputs": [],
"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",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_bkg = \"Arm 1/PID_Active_SP_7V_Mod_1.0_20khz\"\n",
"filepath_bkg = dir + filename_bkg + \".csv\"\n",
"\n",
"background_data = extract_data(filepath_bkg)\n",
"\n",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_data = \"Arm 1/PID_Inactive_SP_7V_Mod_1.0_20khz\"\n",
"filepath_data = dir + filename_data + \".csv\"\n",
"\n",
"data = extract_data(filepath_data)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "354ff9ed",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time_bkg = background_data[:, 0]\n",
"voltage_bkg = background_data[:, 1]\n",
" \n",
"processed_data_bkg, Sxx_bkg = compute_psd(background_data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bad46fa8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time = data[:, 0]\n",
"voltages = data[:, 1]\n",
"\n",
"processed_data, Sxx = compute_psd(data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e11977b3",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAMWCAYAAAAgRDUeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd3hU1dbG35n0UBJqCl2RolQVAVHBi4CoIFICcqV8WC54lWYvl6JioypeuIpKEalSFFRAREAUROko0pSWTHrPJDMp+/tjzJAxmeTs03P2+j1PnsictdZZs+d9c+7se/Y+NsYYA0EQBEEQBEEQBEEQBEHoiN3oBgiCIAiCIAiCIAiCIAjxoEkpgiAIgiAIgiAIgiAIQndoUoogCIIgCIIgCIIgCILQHZqUIgiCIAiCIAiCIAiCIHSHJqUIgiAIgiAIgiAIgiAI3aFJKYIgCIIgCIIgCIIgCEJ3aFKKIAiCIAiCIAiCIAiC0B2alCIIgiAIgiAIgiAIgiB0J9DoBqoDJSUlSEhIQK1atWCz2YxuhyAIgiAIgiAIgiAIwrQwxpCTk4PY2FjY7f7vh6JJKQkkJCSgSZMmRrdBEARBEARBEARBEARRbbh8+TIaN27s9zhNSkmgVq1aADyDWbt27Qpj2rRpA4fDgZiYGPz+++96tkcQpoA8QIgM6Z8QHfIAITKkf0JkSP+EP7Kzs9GkSRPvfIpfGFElWVlZDAA7e/as35iYmBgGgMXExOjYmf4kJiayt99+myUmJlq6DzXrK6klJ5cnR2qslDjygHV6IP3zx5H+rdUHeYA/TgQPkP71rUX6Nx/kAX1rV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2lpf737NmD0aNHY9KkSVi7di2KiorQt29f5OXleWPefvttzJs3D7NmzcJTTz2FOnXqoE+fPj77rEyePBmbNm1CZGQkAI/+77vvPhQXF3tjRo4ciaNHj2Lbtm3Ytm0bjh49ilGjRnmPy/2+UnruNWvWYN++fcjNzS13brUhD+hbq7pcA0T4+w+Q/rWkWk9KTZkyBd26dUOzZs1w66234vnnn8eBAwdQWFgIANixYwd+++03rFy5Ep07d8Zdd92FuXPnYsmSJcjOzuY+X3BwsN9jNpvN57dVCQkJwbXXXouQkBBL96FmfSW15OTy5EiNlRJHHrBOD6R//jjSv7X6IA/wx4ngAdK/vrW01P+2bdswZswY3H777bjpppuwdOlSXLp0CYcOHQLguUtqwYIFeOmllzBkyBDcfvvt+OCDD+B0OrFq1SoAQFZWFj766CPMnTsXoaGhAIA6dergxIkT2LlzJwDg1KlT2LZtGz788EN0794d3bt3x5IlS7B161bvnVlyvq+UPfddd92Fzp07Y+XKlT7nVkKvXr1gs9nK/SQmJpIHdKxVXa4BIvz9B+gaoCnMIqSlpbG4uDjWo0cP72v/+c9/WIcOHXzi0tPTGQC2a9cuybWzsrIYAJaVleU3plGjRgwAa9SoEX/zBGEByAOEyJD+CdEhDxDVmbNnzzIA7MSJE4wxxs6fP88AsMOHD/vEDRw4kI0ePZoxxti3337LALD09HQf/Xfo0IFNmzaNMcbYRx99xCIiIsqdLyIign388ceMMXnfV8qeuyxlz10RY8aMYffff3+517/77jsGgGVkZDDGPN+rHA6H92fw4MGsdevWzOl0+q1NiAv9/Sf8IWUehTHGqvWdUgDw3HPPoUaNGqhXrx4uXbqEzz//3HssMTERUVFRPvF16tRBcHAwEhMT/dZ0uVzIzs72+QGAoqIibd5ENaKoqAipqamGj4XWfahZX0ktObk8OVJjzfK5mwEzjAXpX50c0j8/ZhkL8oA6OeQBPswyDqR/dXJKYwsLCzF16lTcdtttaNeuHQB4vydERUX51Iy
"text/plain": [
"<Figure size 1200x800 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_analysis(processed_data_bkg, processed_data, Sxx_bkg, Sxx, filename_bkg, filename_data, peak_find_threshold=-60)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2522948d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"id": "f91c772c",
"metadata": {},
"outputs": [],
"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",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_bkg = \"Arm 1/PID_Active_SP_7V_Mod_1.0_100khz\"\n",
"filepath_bkg = dir + filename_bkg + \".csv\"\n",
"\n",
"background_data = extract_data(filepath_bkg)\n",
"\n",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_data = \"Arm 1/PID_Inactive_SP_7V_Mod_1.0_100khz\"\n",
"filepath_data = dir + filename_data + \".csv\"\n",
"\n",
"data = extract_data(filepath_data)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f8ad9496",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time_bkg = background_data[:, 0]\n",
"voltage_bkg = background_data[:, 1]\n",
" \n",
"processed_data_bkg, Sxx_bkg = compute_psd(background_data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "1a9afee9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time = data[:, 0]\n",
"voltages = data[:, 1]\n",
"\n",
"processed_data, Sxx = compute_psd(data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3bbcd482",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAMWCAYAAAAgRDUeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd3xUxfrGn930EEIChBBCF0SEi1QFG6ACKgrYUX+KesVyRcV2vSpXQUVFQLyi2Bs2LCgqFhARBQRF6YoISCe99zq/P9asRLLJzO7Zs3POeb6fTz4he9733XfnPA/BcWaOSwghQAghhBBCCCGEEEKIibhD3QAhhBBCCCGEEEIIcR6clCKEEEIIIYQQQgghpsNJKUIIIYQQQgghhBBiOpyUIoQQQgghhBBCCCGmw0kpQgghhBBCCCGEEGI6nJQihBBCCCGEEEIIIabDSSlCCCGEEEIIIYQQYjqclCKEEEIIIYQQQgghphMe6gasQG1tLQ4dOoTmzZvD5XKFuh1CCCGEEEIIIYQQbRFCoKioCO3atYPb7Xs9FCelJDh06BA6dOgQ6jYIIYQQQgghhBBCLMP+/fvRvn17n9c5KSVB8+bNAXgGMz4+vsGYY445BmlpaUhJScFvv/1mZnuEaAE9QJwM9U+cDj1AnAz1T5wM9U98UVhYiA4dOnjnU3wiSJMUFBQIAGLHjh0+Y1JSUgQAkZKSYmJn5pOeni4ef/xxkZ6ebus+jKwfSC1/clVyZGNl4ugB+/RA/avHUf/26oMeUI9zggeof3NrUf/6QQ+YW8sqHqD+7dWHkfXr5lEKCgoajeNB5wrExsb6vFZ31pTdz5xq1qwZBg8ejGbNmtm6DyPrB1LLn1yVHNlYmTh6wD49UP/qcdS/vfqgB9TjnOAB6t/cWtS/ft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sufXJUc2ViZOHrAPj1Q/+px1L+9+qAH1OOc4AHq39xa1L9+0APm1rKKB6h/e/VhZH3Z7XuclJKAZ0oR0jT0AHEy1D9xOvQAcTLUP3Ey1D/xBc+UCgLFxcU+r9XN7dl9jq+4uBgrV65sdCzs0IeR9QOp5U+uSo5srEwcPWCfHqh/9Tjq31590APqcU7wAPVvbi3qXz/oAXNrWcUD1L+9+gjF5+SklAKlpaU+rznFjCUlJVi7di1KSkps3YeR9QOp5U+uSo5srEwcPWCfHqh/9Tjq31590APqcU7wAPVvbi3qXz/oAXNrWcUD1L+9+gjF5+T2PQm4fY+QpqEHiJOh/onToQeIk6H+iZOh/okvuH2PEEIIIYQQQgghhGgLJ6UUyMnJ8XnNKY/CzM7Oxosvvojs7Gxb92Fk/UBq+ZOrkiMbKxNHD9inB+pfPY76t1cf9IB6nBM8QP2bW4v61w96wNxaVvEA9W+vPkLxOTkppUB4eLjPay6Xq953uxIREYG2bdsiIiLC1n0YWT+QWv7kquTIxsrE0QP26YH6V4+j/u3VBz2gHucED1D/5tai/vWDHjC3llU8QP3bq49QfE6eKSUBz5QipGnoAeJkqH/idOgB4mSof+JkqH/iC54pFQRqampC3ULIqampQWFhYcjHIth9GFk/kFr+5KrkyMbqct91QIexoP6NyaH+1dFlLOgBY3LoATV0GQfq35gc6l8dXcaCHjAmhx5QQ5dxsJL+ZeGklAJZWVk+rzllL21mZibmzJmDzMxMW/dhZP1AavmTq5IjGysTRw/YpwfqXz2O+rdXH/SAepwTPED9m1uL+tcPq3ugqKgIkydPRqdOnRATE4MTTzwR69atqxeTkZGByy67DKmpqYiLi8OZZ56JHTt21IvZtWsXzjvvPCQlJSE+Ph4XX3wxMjIy6sWsX78eI0aMQMuWLdG2bVtMmDABxcXF9WK+/vprnHjiiWjevDlSUlJw9913o7q6utH
"text/plain": [
"<Figure size 1200x800 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_analysis(processed_data_bkg, processed_data, Sxx_bkg, Sxx, filename_bkg, filename_data, peak_find_threshold=-60)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d58a4d17",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "960c77bc",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 14,
"id": "27ef8df7",
"metadata": {},
"outputs": [],
"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",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_bkg = \"Arm 1/PID_Active_SP_7V_Mod_0.5\"\n",
"filepath_bkg = dir + filename_bkg + \".csv\"\n",
"\n",
"background_data = extract_data(filepath_bkg)\n",
"\n",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_data = \"Arm 1/PID_Inactive_SP_7V_Mod_0.5\"\n",
"filepath_data = dir + filename_data + \".csv\"\n",
"\n",
"data = extract_data(filepath_data)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "716046fb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time_bkg = background_data[:, 0]\n",
"voltage_bkg = background_data[:, 1]\n",
" \n",
"processed_data_bkg, Sxx_bkg = compute_psd(background_data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "dec099f0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time = data[:, 0]\n",
"voltages = data[:, 1]\n",
"\n",
"processed_data, Sxx = compute_psd(data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "c6317732",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAMWCAYAAAAgRDUeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd3gVVfrHvzcdEkjohI6oFBFB7CiICNgQREAsiA3Xio1dd91dBJW1gVgRFXuhCSqiIiqgYkWaCgoqIi29k3LT5vdHfrkmkpucM3OmZM738zx5Qu687zvvPff7zTw5zDkTMAzDACGEEEIIIYQQQgghDhLhdgOEEEIIIYQQQgghRD84KUUIIYQQQgghhBBCHIeTUoQQQgghhBBCCCHEcTgpRQghhBBCCCGEEEIch5NShBBCCCGEEEIIIcRxOClFCCGEEEIIIYQQQhyHk1KEEEIIIYQQQgghxHE4KUUIIYQQQgghhBBCHCfK7QYaA5WVlThw4ACaNWuGQCDgdjuEEEIIIYQQQgghnsUwDBQUFKBDhw6IiAh/PxQnpQQ4cOAAOnfu7HYbhBBCCCGEEEIIIY2GvXv3olOnTmGPc1JKgGbNmgGoGszmzZvXGdOrVy+kpKQgOTkZP//8s5PtEeIJ6AGiM9Q/0R16gOgM9U90hvon4cjPz0fnzp1D8ylhMUiD5OXlGQCMX375JWxMcnKyAcBITk52sDPnSU1NNR566CEjNTXV132orG+llplcmRzRWJE4esA/PVD/8nHUv7/6oAfk43TwAPXvbC3q33vQA87WaiweoP791YfK+tXzKHl5efXGcaNzCZo2bRr2WPVeU37fcyo+Ph4nnXQS4uPjfd2HyvpWapnJlckRjRWJowf80wP1Lx9H/furD3pAPk4HD1D/ztai/r0HPeBsrcbiAerf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FursXiA+vdXHyrriy7f46SUANxTipCGoQeIzlD/RHfoAaIz1D/RGeqfhIN7StnAwYMHwx6rntvz+xzfwYMH8fnnn9c7Fn7oQ2V9K7XM5MrkiMaKxNED/umB+pePo/791Qc9IB+ngweof2drUf/egx5wtlZj8QD1768+3HifnJSSoKioKOwxXcxYWFiIr7/+GoWFhb7uQ2V9K7XM5MrkiMaKxNED/umB+pePo/791Qc9IB+ngweof2drUf/eo/Lnx5C++UV6wKFajcUDuuif1wD74PI9Abh8j5CGoQeIzlD/RHfoAaIz2uj//WOAtoOB455wuxPiIbTRP5GGy/cIIYQQQgghhBBCiGfhpJQEWVlZYY/p8ijMzMxMPPfcc8jMzPR1HyrrW6llJlcmRzRWJI4e8E8P1L98HPXvrz7oAfk4HTxA/Ttbi/r3HuXlFdi2bRs94FCtxuIBXfTPa4B9cFJKgqioqLDHAoFAre9+JTo6Gu3bt0d0dLSv+1BZ30otM7kyOaKxInH0gH96oP7l46h/f/VBD8jH6eAB6t/ZWtS/9wgEgKZNm9IDDtVqLB7QRf+8BtgH95QSgHtKEdIw9ADRGeqf6A49QHRGG/1zTylSB9ron0jDPaVsoKKiwu0WXKeiogL5+fmuj4Xdfaisb6WWmVyZHNFYr3zuXsALY0H9q8mh/uXxyljQA2py6AE5vDIO1L+aHOpfHsMASktLXR8LekBNDj0gh1fGoTHpXxROSkmQkZER9pgua2nT09Mxd+5cpKen+7oPlfWt1DKTK5MjGisSRw/4pwfqXz6O+vdXH/SAfJwOHqD+na1F/XuP8vJybNmyhR5wqFZj8YAu+uc1wD64fE+A6tvO0tPT0aZNmzpjdLltMRgMYu/evejcuTNiY2N924fK+lZqmcmVyRGNFYmjB/zTA/UvH0f9+6sPekA+TgcPUP/
"text/plain": [
"<Figure size 1200x800 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_analysis(processed_data_bkg, processed_data, Sxx_bkg, Sxx, filename_bkg, filename_data, peak_find_threshold=-60)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c4dc198",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 18,
"id": "05fa8d30",
"metadata": {},
"outputs": [],
"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",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_bkg = \"Arm 1/PID_Active_SP_7V_Mod_0\"\n",
"filepath_bkg = dir + filename_bkg + \".csv\"\n",
"\n",
"background_data = extract_data(filepath_bkg)\n",
"\n",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_data = \"Arm 1/PID_Inactive_SP_7V_Mod_0\"\n",
"filepath_data = dir + filename_data + \".csv\"\n",
"\n",
"data = extract_data(filepath_data)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "1f4a1b8b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time_bkg = background_data[:, 0]\n",
"voltage_bkg = background_data[:, 1]\n",
" \n",
"processed_data_bkg, Sxx_bkg = compute_psd(background_data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "a00aa553",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time = data[:, 0]\n",
"voltages = data[:, 1]\n",
"\n",
"processed_data, Sxx = compute_psd(data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "ebb9c09a",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAMWCAYAAAAgRDUeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd5xU1fnGn5nZXtilw1KkiCIqgmBFKfaOGjWWYI0lamJN/CWxYIu9RKOxxd4RC1hRAREFqYKCgDQp23e272yZmfv747K7LOzsnnPnljP3Pt/Phw+7c9/3nfeeeR4mOZ5zrk/TNA2EEEIIIYQQQgghhNiI3+kGCCGEEEIIIYQQQoj34KQUIYQQQgghhBBCCLEdTkoRQgghhBBCCCGEENvhpBQhhBBCCCGEEEIIsR1OShFCCCGEEEIIIYQQ2+GkFCGEEEIIIYQQQgixHU5KEUIIIYQQQgghhBDb4aQUIYQQQgghhBBCCLGdJKcbSASi0Sjy8/ORnZ0Nn8/ndDuEEEIIIYQQQgghyqJpGqqrq5GXlwe/P/Z6KE5KCZCfn48BAwY43QYhhBBCCCGEEEJIwrB161b0798/5nVOSgmQnZ0NQB/MLl26tBszfPhwFBQUoG/fvlizZo2d7RGiBPQA8TLUP/E69ADxMtQ/8TLUP4lFVVUVBgwY0DKfEhONdEplZaUGQPv1119jxvTt21cDoPXt29fGzuynsLBQe/DBB7XCwkJX92Fm/XhqGcmVyRGNFYmjB9zTA/UvH0f9u6sPekA+zgseoP7trUX9qwc9YG+tRPEA9e+uPsys3zyPUllZ2WEcDzqXICMjI+a15rOm3H7mVGZmJg499FBkZma6ug8z68dTy0iuTI5orEgcPeCeHqh/+Tjq31190APycV7wAPVvby3qXz3oAXtrJYoHqH939eHEffo0TdNse7cEpaqqCjk5OaisrIy5fa9///7Yvn07+vXrh23bttncISHOQw8QL0P9E69DDxAvQ/0TL0P9k1iIzKMAAFdKS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hqamrw7bffdjgWbujDzPrx1DKSK5MjGisSRw+4pwfqXz6O+ndXH/SAfJwXPED921uL+lcPesDeWoniAerfXX04cZ+clJKgrq6u7Qv1pcD654BvfweE9Q/N7Wasra3FwoULUVtb6+o+zKwfTy0juTI5orEicV75QlLBA9S/OTnUvzwq6N+OPugB+TgveID6t7cW9a8e9IC9tRLFA9S/u/pw4j65fU+ANsvOUpuAbR8C22cC/jRgwJlA3+PQf489sb2wDP16pmPb8veAvscB/qTdi0WbgLJFQMGXQOVPwCH/A1Jy7b4lQkyHS3eJl6H+idehB4iXof6Jl6H+SSxEt++1M2tCYvLd+UB2BtD/DOCw14Dk7NZrgTT97+RcoGo1sPYxoNtBwJBLAGhA4ZdA0VwgEgK6HwzknQD0OQpY/lfgkOcduBlCCCGEEEIIIYQQ5+D2PQmCe/4LOOJdYNB5bSeksNOjMDUA+9wMTJoF9D8NWPMIsO5JIGMAcOj/gIkfA/vfDvQ4FOg1HkjKBvI/d+BujFFaWornn38epaWlru7DzPrx1DKSK5MjGisS55XHwargAerfnBzqXx4V9G9HH/SAfJwXPED921uL+lcPesDeWoniAerfXX04cZ9cKSVBIK1rzGs+n6/N3/D59ImnHod2XPSAe4BvTgV6HAak5JjVqmUkJyejT58+SE5OdnUfZtaPp5aRXJkc0ViRuN084FJU8AD1b04O9S+PCvq3ow96QD7OCx6g/u2tRf2rBz1gb61E8QD1764+nLhPniklgMheyLj20hZ/C2x+Azj4GRO6JcQZuJ+ceBnqn3gdeoB4GeqfeBnqn8RC9Ewpbt+TIBKJWFO415GAP1U//FxxIpE
"text/plain": [
"<Figure size 1200x800 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_analysis(processed_data_bkg, processed_data, Sxx_bkg, Sxx, filename_bkg, filename_data, peak_find_threshold=-60)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "699f9f52",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 23,
"id": "67f9cd80",
"metadata": {},
"outputs": [],
"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",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_bkg = \"Arm 2/PID_Active_SP_9V\"\n",
"filepath_bkg = dir + filename_bkg + \".csv\"\n",
"\n",
"background_data = extract_data(filepath_bkg)\n",
"\n",
"dir = str(globals()['_dh'][0]).replace('\\\\','/') + \"/Time Series Data/\"\n",
"filename_data = \"Arm 2/PID_Inactive_SP_9V\"\n",
"filepath_data = dir + filename_data + \".csv\"\n",
"\n",
"data = extract_data(filepath_data)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "be833e35",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time_bkg = background_data[:, 0]\n",
"voltage_bkg = background_data[:, 1]\n",
" \n",
"processed_data_bkg, Sxx_bkg = compute_psd(background_data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "a37ab5b3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculating power spectrum...\n"
]
}
],
"source": [
"# Extract the first and second columns from data_array\n",
"time = data[:, 0]\n",
"voltages = data[:, 1]\n",
"\n",
"processed_data, Sxx = compute_psd(data, new_sampling_rate = 1000000)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "e5ca8ba3",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAA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clJLgjdVvYPqK6Xh3zbuYvX42/rvxv1iYuRDfb/keRVVFAPxvxvLycixatAjl5eW+7kNl/Whq2cmVyRGNFYkz5QtJBw9Q/2pyqH95dNC/E33QA/JxJniA+ne2FvWvH/SAs7W84gHq3199uDFObt8ToPG2M9wOIDlC0MMASsHbFomx8NZdYjLUPzEdeoCYDPVPTIb6J5EQ3b4X72BPnmfhxIVIb5+O5PhkpCSkIDk+GfHBeBzy0iFYhVUAgLIad2/nI4QQQgghhBBCCPEC3L4nQUZ8BvZJ3we903qjc6vOaJvUFqkJqXh+3PPhmJLqEmQWZ7rYZWzJy8vDiy++iLy8PF/3obJ+NLXs5MrkiMaKxJnyOFgdPED9q8mh/uXRQf9O9EEPyMeZ4AHq39la1L9+0APO1vKKB6h/f/Xhxji5KCVBfHzzN5Yd2vNQpCakAmjYS3vNnGt8u6c2ISEBXbt2RUJCgq/7UFk/mlp2cmVyRGNF4gKBQJP/+hUdPED9q8mh/uXRQf9O9EEPyMeZ4AHq39la1L9+0APO1vKKB6h/f/Xhxjh5ppQAInshu3fvju3btwNtANwMzDpzFk7Z7xRnGyXERbifnJgM9U9Mhx4gJkP9E5Oh/kkkRM+U4p1SEtTV1UW89ueV4WvnXovS6tJYt+Q4dXV1KCkpaXEu/NCHyvrR1LKTK5MjGqvL564DOswF9a8mh/qXR5e5oAfU5NADcugyD9S/mhzqXx5d5oIeUJNDD8ihyzx4Sf+
"text/plain": [
"<Figure size 1200x800 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_analysis(processed_data_bkg, processed_data, Sxx_bkg, Sxx, filename_bkg, filename_data, peak_find_threshold=-60)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3ed4e40e",
"metadata": {},
"outputs": [],
"source": []
}
],
"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
}