# how to cut off frequencies above 10 Hz with Welch method

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

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[1] - freqs[0]  # = 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)


• What's your question? Does your code not work? – endolith Jul 12 at 18:38
• The code works, but the relative power value includes the power of frequencies beyond 10 Hz, of which is largely noise. I would like to remove everything above 10 Hz so that the relative poser calculation can be more accurate. – Tau Lambda Jul 12 at 19:05
• perhaps a more direct question would be, how to apply a 4th order butterworth to the data to cut off frequencies above 10 Hz. – Tau Lambda Jul 12 at 19:22
• You could calculate power directly from the spectrum and just ignore everything outside of that range. gist.github.com/endolith/1257010 – endolith Jul 12 at 19:24