import scipy.signal as signal import numpy as np import matplotlib.pyplot as plt # Read a file that has one integer per line, and was sampled at 500 Hz. # Subtract off the mean, so it's a zero-mean signal (this makes the FFT much # more reasonable). # Then return the resulting numpy array. # The 'beg' and 'end' arguments allow you to subset just a portion of the file; # e.g., to use only one heartbeat so that the resulting file will just repeat # the one heartbeat over and over, making it very repeatable. def read_data_file (fname, beg=0, end=None): data = read_data_file_raw (fname, beg, end) return (data - np.mean(data)) # Read an input file just like read_data_file(). This time, just print it out # again, but with 10 values per line, and comma-separated. # This makes it easy for an .c file to include it and make it part # of an array definition. def convert_csv_to_disco (fname, beg=0, end=None): import math, re data = read_data_file_raw (fname, beg, end) # Change the output file name so we don't overwrite the original file. outfile_name = fname if (re.search ("\..?.?.?$", fname)): outfile_name = re.sub ("\..?.?.?$", ".c_data", outfile_name, 1) outfile = open (outfile_name, "w") # Now output it, 10 values/line. n_rows = math.floor (data.size/10) for i in range (n_rows): s = ",".join ([str(int(n)) for n in data[i*10:(i+1)*10]]) if (i