from scipy.fftpack import fft
#import plotly
#import chart_studio.plotly as py
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.widgets import Cursor
from gekko import GEKKO
#%matplotlib qt
new_x=np.arange(0,3.5e-05,1/(1e7))
dataset_fft=pd.read_table("sinus_1mhz.txt")
array_fft=dataset_fft.values
m=GEKKO()
m.x=m.Param(new_x)
m.y=m.Var()
m.cspline(m.x,m.y,array_fft[:,0],array_fft[:,1])
m.options.IMODE=2
m.solve(disp=False)
fig=plt.figure()
ax=fig.subplots()
ax.grid()
cursor=Cursor(ax, horizOn=True,vertOn=True,useblit=True,color='r',linewidth =1)
#plt.plot(array_fft[:,0],array_fft[:,1])
plt.plot(m.x,m.y)
plt.xlabel("time")
plt.ylabel("amp")
plt.show()
Do you want us to read the documentation for you? I don't even know what exact FFT library you use.do i have to follow this "power of two" law in my FFT?
I agree with various replies. Just adding few notes.Hello, i have a signal 3.5*10^-5 sec long as shown bellow.
It was unevenly sampled so i did cubic spine interpolation.
my signal as shown in time domain about 0.9V and 1Mhz frequency.
I want to create an accurate fft picture with Fs=10Mhz So Ts=10^-7 sec
N=signal 3.5*10^-5/10^-7=350
I want an accurate FFT with 1Hz bin 350 samples is too little.(spectral leakage)
what could be done to perform a good fft in this case?
Thanks.
View attachment 182123Code:from scipy.fftpack import fft #import plotly #import chart_studio.plotly as py import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib.widgets import Cursor from gekko import GEKKO #%matplotlib qt new_x=np.arange(0,3.5e-05,1/(1e7)) dataset_fft=pd.read_table("sinus_1mhz.txt") array_fft=dataset_fft.values m=GEKKO() m.x=m.Param(new_x) m.y=m.Var() m.cspline(m.x,m.y,array_fft[:,0],array_fft[:,1]) m.options.IMODE=2 m.solve(disp=False) fig=plt.figure() ax=fig.subplots() ax.grid() cursor=Cursor(ax, horizOn=True,vertOn=True,useblit=True,color='r',linewidth =1) #plt.plot(array_fft[:,0],array_fft[:,1]) plt.plot(m.x,m.y) plt.xlabel("time") plt.ylabel("amp") plt.show()
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 30 13:04:11 2023
@author: Asus
"""
import math
from scipy.fftpack import fft
#import plotly
#import chart_studio.plotly as py
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.widgets import Cursor
from gekko import GEKKO
#%matplotlib qt
new_x=np.arange(0,7.89752e-05,1/(1e7))
dataset_fft=pd.read_table("sinus_1mhz.txt")
array_fft=dataset_fft.values
m=GEKKO()
m.x=m.Param(new_x)
m.y=m.Var()
m.cspline(m.x,m.y,array_fft[:,0],array_fft[:,1])
m.options.IMODE=2
m.solve(disp=False)
freq_vec=1e7*np.arange(0,1,1/(1e7))
m2=np.pad(m.y, (0,100000-len(m.y)), 'constant')
fft_y=fft(m2,len(freq_vec))
fig=plt.figure()
ax=fig.subplots()
ax.grid()
cursor=Cursor(ax, horizOn=True,vertOn=True,useblit=True,color='r',linewidth =1)
plt.plot(freq_vec,20*np.log10(abs(fft_y)/max(abs(fft_y))))
plt.xlabel("Freq")
plt.ylabel("amp_normalised")
plt.show()
The raw data tells me it is 1/8 MHz and 1 MHz doing my eyeball inversion of 20 us of raw data.I removed dc offset then did fft without descaling. FFT tells me your tone is @ ~390KHz assuming Fs is 10Msps.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?