diff --git a/scope_fft/scope_fft.py b/scope_fft/scope_fft.py new file mode 100644 index 0000000..7a7cbe5 --- /dev/null +++ b/scope_fft/scope_fft.py @@ -0,0 +1,45 @@ +import numpy as np +import matplotlib.pyplot as plt + +def sig_fft(file1, file2): + # Load data from CSV files + data = np.genfromtxt(file1, delimiter=',')[2:] + data2 = np.genfromtxt(file2, delimiter=',')[2:] + + # find where data is nan + n_index = np.argmax(np.isnan(data[:,1])) + n_index2 = np.argmax(np.isnan(data2[:,1])) + # Define each column + time = data[:n_index, 0] + rx_signal = data[:n_index, 1] + tx_signal = data[:n_index, 2] + num_samples = time.size + fs1 = 1 / (time[1] - time[0]) # Set sampling frequency + + # Define each column for data 2 + time2 = data2[:n_index2, 0] + rx_signal2 = data2[:n_index2, 1] + tx_signal2 = data2[:n_index2, 2] + num_samples2 = time2.size + fs2 = 1 / (time2[1] - time2[0]) # Set sampling frequency + # Plot raw data + plt.figure(1) + plt.plot(time, rx_signal, label='Data 1') + plt.plot(time2, rx_signal2, label='Data 2') + plt.title('Unfiltered Data') + plt.legend() + + # fft for data 1 + sigfft = np.fft.fft(rx_signal) + freq = np.fft.fftfreq(rx_signal.shape[-1], 1/(fs1)) + # fft for data 2 + sigfft2 = np.fft.fft(rx_signal2) + freq2 = np.fft.fftfreq(rx_signal2.shape[-1], 1/(fs2)) + # plot fft + plt.figure(2) + plt.plot(freq, np.abs(sigfft), label='Data 1') + plt.plot(freq2, np.abs(sigfft2), label='Data 2') + plt.title('FFT of Data') + plt.xlim(0, 20000) + + plt.show()