<jupyter_start><jupyter_text>Introduction to ElectrophysiologyThe goal of this python notebook is to introduce some basic concepts of electrophysiology Local Field PotentialsNeurons are electrically active. As large groups of neurons synchronize this activity, their small electrical signals add up.Let's set up a synthetic signal first, to see what kinds of things we can do with LFPs<jupyter_code>import numpy as np

t = np.linspace(0,10,2000) #we're setting up a time array from 0 to 10 seconds, with 1000 samples
fs = 1/((t[-1] - t[0]) / t.shape[0]) #we're finding the sampling rate directly from the t array

#now we set up a synthetic measured signal. we set this up in time domain first
y = 5 * np.sin(2 * np.pi * t) + 2 * np.sin(2 * np.pi * 60 * t)

import matplotlib.pyplot as plt #and import the plotting library
#we want the plots to show up in the notebook
%matplotlib inline 

plt.figure()
plt.plot(t,y) #plot our t vs y

plt.show() #show the figure<jupyter_output><empty_output><jupyter_text>Now, to be honest, this doesn't look like any real LFP. If you saw this in your signal, you would quickly raise a red flag and try to figure out where this is coming from. One way to do that is to look at the *Fourier Domain* of the signal. We know the lights in our recording room are on the power grid, and we know the power grid uses 60Hz signals. Let's see if we have a peak at 60Hz<jupyter_code>import scipy.signal as sig

print('Our sampling rate is: ' + str(fs))
F,Pxx = sig.welch(y,fs=fs)

plt.figure()
plt.plot(F,np.abs(Pxx))
plt.show()<jupyter_output>Our sampling rate is: 200.0
{'fraction_non_alphanumeric': 0.07904642409033877, 'fraction_numerical': 0.020075282308657464, 'mean_word_length': 4.4436860068259385, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '233957', 'license': 'MIT', 'n_tokens_mistral': 535, 'n_tokens_neox': 489, 'n_words': 241, 'path': 'Intro Electrophysiology.ipynb', 'repo_name': 'virati/SigProc_DBSEphys', 'size': '1594'}