[英]Python, FFT and DC offset analysis
I test an FFT on a square signal (100Hz, 0V-5V) of 50% duty cycle and i don't understand why my DC offset is huge?我在占空比为 50% 的方波信号(100Hz,0V-5V)上测试 FFT,但我不明白为什么我的 DC 偏移量很大?
In theory it should be 2.5V?理论上应该是2.5V?
Thanks, Best regards.谢谢,最好的问候。
The fundamental is ok and others harmonics are correct.基波正常,其他谐波正确。
square signal 100Hz, TTL compatible 0V-5V, 50% duty cycle方波信号100Hz,TTL兼容0V-5V,50%占空比
FFT, DC offset problem, fundamental ok, harmonics ok FFT,直流偏移问题,基波正常,谐波正常
from scipy.fftpack import fft
from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
#
# configuration
# time analyse = L * (1/Fsample)
#
L = 512 # lenght buffer
Fsample = 2000 # frequency sample
Fsignal = 100 # frequency
#********************************
# perdiode sample
Tsample = 1.0/Fsample
# time vector, start = 0s, stop = 0.1024s, step = (0.1024s / (1/Fe))
t = np.linspace(0.0, L*Tsample, L)
# signal definition, DC offet = 2.5V, Amplitude = 2.5V
signal = 2.5 + 2.5*signal.square(2 * np.pi * Fsignal * t, 0.5)
# plot time signal
plt.subplot(2,1,1)
plt.plot(t, signal)
# fft of time signal
yf = fft(signal)
# time vector of fft
xf = np.linspace(0.0, 1.0/(2.0*Tsample), L//2)
# plot spectral
plt.subplot(2,1,2)
plt.plot(xf, 2.0/L * np.abs(yf[0:L//2]))
On the last line, the normalization factor was wrong.在最后一行,归一化因子是错误的。
It was not 2/L
but 1/L
.不是
2/L
而是1/L
。
The correct normalization factor plt.plot(xf, 1.0/L * np.abs(yf[0:L//2]))
正确的归一化因子
plt.plot(xf, 1.0/L * np.abs(yf[0:L//2]))
The code work fine now !代码现在工作正常!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.