import numpy as np
import matplotlib.pyplot as plt
Chapter 6
Chapter 6
Analyzing Neural Time Series Data
Python code for Chapter 6 – converted from original Matlab by AE Studio (and ChatGPT)
Original Matlab code by Mike X Cohen
This code accompanies the book, titled “Analyzing Neural Time Series Data” (MIT Press).
Using the code without following the book may lead to confusion, incorrect data analyses, and misinterpretations of results.
Mike X Cohen and AE Studio assume no responsibility for inappropriate or incorrect use of this code.
Import necessary libraries
Figure 6.2
# Create sine wave
= 1000
srate = np.arange(0, 1, 1/srate)
time = 3
frequency
= np.sin(2 * np.pi * frequency * time)
sinewave
# Plot the continuous sine wave and sampled sine waves
=(10, 8))
plt.figure(figsize
# Continuous sine wave
311)
plt.subplot('r')
plt.plot(time, sinewave, -.05, time[-1] * 1.05])
plt.xlim([-1.1, 1.1])
plt.ylim(['continuous sine wave')
plt.title(= np.round(np.linspace(0, len(time)-1, frequency*2)).astype(int)
sampling1 'o')
plt.plot(time[sampling1], sinewave[sampling1],
# Sampled at 2*frequency
312)
plt.subplot('-o')
plt.plot(time[sampling1], sinewave[sampling1], -.05, time[-1] * 1.05])
plt.xlim([-1.1, 1.1])
plt.ylim(['sampled at 2*frequency')
plt.title(
# Sampled at 20*frequency
= np.round(np.linspace(0, len(time)-1, frequency*20)).astype(int)
sampling2 313)
plt.subplot('-+')
plt.plot(time[sampling2], sinewave[sampling2], 'sampled at 20*frequency')
plt.title(-.05, time[-1] * 1.05])
plt.xlim([-1.1, 1.1])
plt.ylim([
plt.tight_layout() plt.show()