From 732f4d39a9d66a2b107c89e1af14226dbeea2b0e Mon Sep 17 00:00:00 2001 From: mbergmann Date: Thu, 24 Oct 2024 09:51:47 +0200 Subject: [PATCH] [useful_functions.py] added sam_spectrum function --- code/useful_functions.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/code/useful_functions.py b/code/useful_functions.py index edea81b..9f56b57 100644 --- a/code/useful_functions.py +++ b/code/useful_functions.py @@ -399,6 +399,39 @@ def sam_data(sam): avg_dur = np.mean(durations) return avg_dur, sam_amp, sam_am, sam_df, sam_eodf, sam_nyquist, sam_stim +def sam_spectrum(sam): + """ + Creates a power spectrum for a ReproRun of a SAM. + + Parameters + ---------- + sam : ReproRun Object + The Reprorun the powerspectrum should be generated from. + + Returns + ------- + sam_frequency : np.array + The frequencies of the powerspectrum. + sam_power : np.array + The powers of the frequencies. + + """ + stimuli = sam.stimuli + # lists for the power spectra + frequencies = [] + powers = [] + # loop over the stimuli + for stimulus in stimuli: + # get the powerspectrum for each stimuli + frequency, power = power_spectrum(stimulus) + # append the power spectrum data + frequencies.append(frequency) + powers.append(power) + #average over the stimuli + sam_frequency = np.mean(frequencies, axis = 0) + sam_power = np.mean(powers, axis = 0) + return sam_frequency, sam_power + def spike_times(stim): """ Reads out the spike times and other necessary parameters