Skip to content
Permalink
238fa7537c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
61 lines (38 sloc) 1.34 KB
from __future__ import division
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import numpy.fft as dft
inputfp = np.loadtxt("ECGSamples.txt", dtype= np.float16)
inputea = np.loadtxt("ECGSamples.txt", dtype= np.float128)
import random
import math
import cmath
plt.close()
time_step = 1 / 30
freqsfp = dft.fftfreq(inputfp.size, time_step)
freqsea = dft.fftfreq(inputea.size, time_step)
idxfp = np.argsort(freqsfp)
idxea = np.argsort(freqsea)
# FFT, Floating Point
fft_fp_data = np.abs(dft.fft(inputfp)) ** 2#We don't want imaginaries! Messes up our data!
#plt.figure()
#plt.plot(freqsfp[idxfp],fft_fp_data[idxfp], 'r')
#plt.xlabel('frequency [Hz]')
#plt.ylabel('Linear Spectrum [V RMS]')
fft_ea_data = np.abs(dft.fft(inputea)) ** 2
np.savetxt("FFT_FP.csv", fft_fp_data, delimiter=",")
np.savetxt("freqs.csv", freqsea, delimiter=",")
np.savetxt("FFT_EA.csv", fft_ea_data,delimiter=",")
#
# plt.plot(freqs[idx],fft_fp_data[idx])
# FFT, Exact Arithmetic
# It always computes the exact answers, just matters if you're importing it as a float or arithmetic
#eadata = inputt.astype(Decimal)
#
#plt.plot(freqsea[idxea],fft_ea_data[idxea], 'b')
#fft_xact_data = np.abs(dft.fft(input)) ** 2
#np.savetxt("FFT_XACT.csv", fft_xact_data, delimiter=",")
# Prime Algorithm, Floating Point
# Prime Algorithm, Exact Arithmetic
plt.show()