Added find_AM

This commit is contained in:
Diana 2024-10-25 17:16:15 +02:00
parent 447e88b212
commit 2947782652

View File

@ -1,6 +1,8 @@
import numpy as np import numpy as np
import rlxnix as rlx import rlxnix as rlx
from scipy.signal import welch from scipy.signal import welch
from scipy import signal
import matplotlib.pyplot as plt
def all_coming_together(freq_array, power_array, points_list, categories, num_harmonics_list, colors, delta=2.5, threshold=0.5): def all_coming_together(freq_array, power_array, points_list, categories, num_harmonics_list, colors, delta=2.5, threshold=0.5):
# Initialize dictionaries and lists # Initialize dictionaries and lists
@ -249,41 +251,20 @@ def extract_stim_data(stimulus):
amp_mod, ny_freq = AM(eodf, stim_freq) amp_mod, ny_freq = AM(eodf, stim_freq)
return amplitude, df, eodf, stim_freq, stim_dur, amp_mod, ny_freq return amplitude, df, eodf, stim_freq, stim_dur, amp_mod, ny_freq
def find_exceeding_points(frequency, power, points, delta, threshold): def find_AM(frequency, eodf, nyquist, stimulus_frequency):
""" t = signal.windows.triang(eodf) * nyquist
Find the points where the integral exceeds the local mean by a given threshold. length_t2 = len(frequency) // eodf
length_t2 = int(length_t2)
t2 = np.tile(t, length_t2)
x_values = np.arange(len(t2))
Parameters fig, ax = plt.subplots()
---------- ax.plot(t2)
frequency : np.array ax.scatter(stimulus_frequency, t2[np.argmin(np.abs(x_values - stimulus_frequency))])
An array of frequencies corresponding to the power values. plt.grid()
power : np.array
An array of power spectral density values.
points : list
A list of harmonic frequencies to evaluate.
delta : float
Half-width of the range for integration around the point.
threshold : float
Threshold value to compare integrals with local mean.
Returns
-------
exceeding_points : list
A list of points where the integral exceeds the local mean by the threshold.
"""
exceeding_points = []
for point in points:
# Calculate the integral and local mean for the current point
integral, local_mean = calculate_integral(frequency, power, point, delta)
# Check if the integral exceeds the threshold
valid, message = valid_integrals(integral, local_mean, threshold, point)
if valid:
exceeding_points.append(point)
return exceeding_points AM = t2[np.argmin(np.abs(x_values - stimulus_frequency))]
return fig, AM
def firing_rate(binary_spikes, dt = 0.000025, box_width = 0.01): def firing_rate(binary_spikes, dt = 0.000025, box_width = 0.01):
''' '''