Python,FFT和DC偏移分析

问题描述 投票:0回答:1

我在占空比为50%的方波信号(100Hz,0V-5V)上测试FFT,我不明白为什么我的DC偏移很大吗?

理论上应该是2.5V吗?

谢谢,最好的问候。

基本没问题,其他谐波都正确。

square signal 100Hz, TTL compatible 0V-5V, 50% duty cycle

FFT, DC offset problem, fundamental ok, harmonics ok

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]))
python fft offset dc
1个回答
0
投票

在最后一行,归一化因子是错误的。

不是2/L,而是1/L

正确的归一化因子plt.plot(xf, 1.0/L * np.abs(yf[0:L//2]))

代码现在可以正常工作!

FFT correct amplitude

© www.soinside.com 2019 - 2024. All rights reserved.