Advertisement
Guest User

lowpass_filter list+dict

a guest
Dec 11th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. def lowpass_filter(channels,
  2.                    cutoff_freq=35,
  3.                    sample_rate=175,
  4.                    filter_order=7):
  5.     """Filters channels with butterworth lowpass filter.
  6.  
  7.    Args:
  8.  
  9.        channels: list of ECG channels.
  10.        cutoff_freq: cutoff freq in Hz used in filter, defaults to 35.
  11.        sample_rate: sample rate of channel, defaults to 175.
  12.        filter_order: filter order, defaults to 7.
  13.  
  14.    Returns: filtered list of channels."""
  15.     is_dict = isinstance(channels, dict)
  16.  
  17.     if is_dict:
  18.         filtered_channels = {}
  19.     else:
  20.         filtered_channels = []
  21.  
  22.     for channel in channels:
  23.         curr_channel = channels[channel] if is_dict else channel
  24.         filtered_channel = butter_lowpass_filter(curr_channel,
  25.                                                  cutoff_freq=cutoff_freq,
  26.                                                  sample_rate=sample_rate,
  27.                                                  filter_order=filter_order)
  28.  
  29.         if is_dict:
  30.             filtered_channels[channel] = filtered_channel
  31.         else:
  32.             filtered_channels.append(filtered_channel)
  33.  
  34.     return filtered_channels
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement