Hi everyone,
I am trying to just FFT four cosines but the results are weird.
This code below gives the following figures:
https://imgur.com/a/FP3ylak
https://imgur.com/a/ZjTedft
So somehow the spacing is ruining the FFT.
I am trying to just FFT four cosines but the results are weird.
This code below gives the following figures:
https://imgur.com/a/FP3ylak
import numpy as np import scipy.fftpack from scipy.fftpack import fftfreq from scipy.fft import fft from scipy.fft import fft2 from scipy.fft import fftn from scipy.signal import blackman, flattop, boxcar import matplotlib.pyplot as plt import random plt.rcParams['figure.figsize'] = [9, 5] gamma = 2.8e6 # short for gamma/2*pi, in Hz, [Hz/G] tau = 1e-6 # us; G = np.linspace(0, 1.7e6, 2400) # G_max is 1.7G/um ~ 1.7e6G/m k = gamma*G*tau # 1/nm rx = np.linspace(404e-7,416e-7,4) outer = np.outer(rx,k) y = 0.5*np.cos(2*np.pi*outer) #+ np.random.normal(0, .1, k.shape) yy = np.sum(y,axis=0) plt.figure(0) # #plt.xlim(1.0e8, 1.3e8) plt.plot(k, yy) f = fftfreq(len(k), np.diff(k)[0]) yf = fft(yy) plt.figure(1) plt.xlim(0, 500e-7) plt.plot(f[:G.size//2], np.abs(yf[:G.size//2])) r_max = f[:G.size//2][np.argmax(np.abs(yf[:G.size//2]))] amplitude_max = np.abs(yf[:G.size//2]).max()I would have figured, that the FFT would be just 4 spikes but not something like this. If I change rx to rx = np.linspace(404e-7,4016e-7,4) I get this:
https://imgur.com/a/ZjTedft
So somehow the spacing is ruining the FFT.