This is the first time I have worked with any code so I am rather unfamiliar with all the lingo and processes involved. I am trying to convert a signal to the frequency domain and want to find the spectral power within the 0.5-1.0 frequency band. I have the code to produce the relative power within this band, but I know that above 10 Hz it is largely noise and I would like to remove it so it does not interfere with the relative power calculation. This is the code I have been using.
import numpy as np data = np.loadtxt('Post_EO_Foam_CTRL.txt') import matplotlib.pyplot as plt import seaborn as sns sns.set(font_scale=1.2) # Define sampling frequency and time vector sf = 200. time = np.arange(data.size) / sf from scipy import signal # Define window length (4 seconds) win = 4* sf freqs, psd = signal.welch(data, sf, nperseg=win) # Define prop lower and upper limits low, high = 0.5, 1 # Find intersecting values in frequency vector idx_prop = np.logical_and(freqs >= low, freqs <= high) from scipy.integrate import simps # Frequency resolution freq_res = freqs - freqs # = 1 / 4 = 0.25 # Compute the absolute power by approximating the area under the curve prop_power = simps(psd[idx_prop], dx=freq_res) print('Absolute prop power: %.7f mV^2' % prop_power) # Relative delta power (expressed as a percentage of total power) total_power = simps(psd, dx=freq_res) prop_rel_power = prop_power / total_power print('Relative prop power: %.3f' % prop_rel_power)