4

I have found the following method to downsample a signal in python. I would like to use this method with a sample_rate of 100.21 but I think currently it only works for integer powers of two. Is there a possibility to downsample my signal with frequency 100.21 Hz to 8 Hz?

def interpolateDataTo8Hz(data,sample_rate,startTime):
    # Downsample
    idx_range = range(0,len(data))
    data = data.iloc[idx_range[0::int(sample_rate)/8]]

    # Set the index to be 8Hz
    data.index = pd.DatetimeIndex(start=startTime,periods = len(data),freq='125L')

    # Interpolate all empty values
    data = interpolateEmptyValues(data)
    return data

def interpolateEmptyValues(data):
    cols = data.columns.values
    for c in cols:
        data[c] = data[c].interpolate()

    return data
smci
  • 32,567
  • 20
  • 113
  • 146
machinery
  • 5,972
  • 12
  • 67
  • 118
  • Possible duplicate of [Downsample a 1D numpy array](https://stackoverflow.com/questions/20322079/downsample-a-1d-numpy-array) – ivan_pozdeev May 12 '18 at 00:02
  • 1
    do want to avoid alising? if so, you need a sub 4 Hz filter before decimating, then "rational fraction" resampling can achieve the decimation correctly – f5r5e5d May 13 '18 at 01:32

0 Answers0