Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

performing high precision fft in pyhon

yefj

Advanced Member level 3
Advanced Member level 3
Joined
Sep 12, 2019
Messages
756
Helped
0
Reputation
0
Reaction score
2
Trophy points
18
Activity points
4,202
Hello, i have build an amplifier which creates an analog signal at DC=1.8 and f=1Mhz with amplitude of 57.106822mV
I have sampled my signal at Ts=2.179398748773332e-08.
I want to do FFT with 1Hz bin so signal_duration = 45.8 million * 2.179398748773332e-08 seconds=1 sec as shown in the directive bellow.
so i expect to see FFT plot 0..45.8MHz(simtric plot)
i extracted the table and built FFT code in python as shown bellow.
As you can see my AC signal is displayed at 2MHz instead f 1MHz
Where did i go wrong?
Thanks.

1680276323122.png


1680273406256.png

1680277726862.png

Code:
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
#%matplotlib qt
dataset_fft=pd.read_table("sinus_1mhz.txt")

array_fft=dataset_fft.values
Ts=array_fft[4][0]-array_fft[3][0];
Fs=1/Ts #Hz
L=np.size(array_fft)
freq_vec=Fs*np.arange(0,1,1/np.size(array_fft))
#L=np.size(freq_vec)/2
fft_y=fft(array_fft[:,1],L)
fig=plt.figure()
ax=fig.subplots()
ax.grid()
cursor=Cursor(ax, horizOn=True,vertOn=True,useblit=True,color='r',linewidth =1)
#ax.plot(array_fft[:,0],array_fft[:,1])
ax.plot(freq_vec,abs(fft_y)/np.size(array_fft))
plt.show()
 

kaz1

Full Member level 5
Full Member level 5
Joined
Aug 15, 2019
Messages
254
Helped
16
Reputation
32
Reaction score
35
Trophy points
28
Location
UK
Activity points
1,544
Judging from your time domain each cycle is 1 microsec implying 1MHz.
If fft is saying it is 2MHz then check your Fs value and freq scaling from running code.
 

FvM

Super Moderator
Staff member
Advanced Member level 7
Joined
Jan 22, 2008
Messages
51,221
Helped
14,653
Reputation
29,584
Reaction score
13,799
Trophy points
1,393
Location
Bochum, Germany
Activity points
292,770
How do you generate the output file? Setting maximum timestep in transient simulation parameters doesn't generate a waveform file with equidistant sample points.
 
  • Like
Reactions: yefj

    yefj

    Points: 2
    Helpful Answer Positive Rating

KlausST

Super Moderator
Staff member
Advanced Member level 7
Joined
Apr 17, 2014
Messages
23,525
Helped
4,761
Reputation
9,543
Reaction score
5,180
Trophy points
1,393
Activity points
156,067
Hi

When I see values with 15 decimals ... I automatically guess you don't know what you are doing.
Can you reproduce the value down to 4 decimals, or 5?

This also fits to a sampling rate of 45MHz and an FFT with 1Hz resolution.
I can't imagine an application where this makes sense.

Additionally expecting the FFT result to go up to 45MHz ... while the sampling rate is 45MHz...

****
Please decide what resolutions you really need

And please learn about FFT.
Basically most FFT algorithms expect an input value count of 2^n, so either 33.5 million or 67 million, but not 45 million.
The max output frequency is always below half sampling frequency.
While possible to use an FFT with millions of input samples, I can't remember seen one above 65k samples.
If I'm not mistaken then calculation time rises at least squared to input count.... so rising input count from 65k to 67 million may cause the calculation to increase by a factor of 1 million. Like from 10ms to 10,000s .. which means hours...
****

Klaus
 

yefj

Advanced Member level 3
Advanced Member level 3
Joined
Sep 12, 2019
Messages
756
Helped
0
Reputation
0
Reaction score
2
Trophy points
18
Activity points
4,202
Hello FVM, you are correct.
This is a problem.
How do i deside in LTSPICE the exact sampling rate of a my sinous signal?
I cant see how do i change the sample rate of this, or make it absolutely constant.Its not "equidistant".
Is there something you could reccomend me?
Thanks.

etting maximum timestep in transient simulation parameters doesn't generate a waveform file with equidistant sample points."
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top