您当前的位置: 首页 >  Python

星拱北辰

暂无认证

  • 0浏览

    0关注

    1205博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Python】可视化的离散傅里叶变换+快速傅里叶变换后时域信号的频域分析

星拱北辰 发布时间:2019-11-08 12:25:42 ,浏览量:0

前面的知识这里就不介绍了,下面是Python语言实现的离散傅里叶变换的处理:

时域信号的函数表达

要处理的时域信号: f ( t ) = s i n ( t ) + 2 s i n ( 3 t ) + 2 c o s ( 2 t ) + 4 s i n ( 15 t ) f(t) = sin(t) + 2sin(3t) + 2cos(2t) + 4sin(15t) f(t)=sin(t)+2sin(3t)+2cos(2t)+4sin(15t)

绘制函数图像
import numpy as np

import matplotlib.pyplot as plt

def f(x):
    return np.sin(x) + 2*np.sin(3*x) + 2*np.cos(3*x) + 4*np.sin(15*x)

x = np.linspace(0, 2*np.pi, 2048)

plt.scatter(x, f(x))

plt.grid

plt.show()

下面是可视化出来的时域中信号在一个2π周期内的形态: 在这里插入图片描述

Python的fft工具对这段时域信号进行频域分析
import numpy as np

from scipy.fftpack import fft

import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi, 128)
y = np.sin(x) + 2*np.sin(3*x) + 2*np.cos(3*x) + 4*np.sin(15*x)

# 离散频率
xf = np.arange(len(y))

# 由于对称性,因此只取一半区域
xf_half = xf[range(int(len(x)/2))]

# 执行完fft以后,对各频率的能量进行归一化处理
yf = abs(fft(y))/len(x)

# 由于对称性,因此只取一半区间
yf_half = yf[range(int(len(x)/2))]

plt.plot(xf_half, yf_half)

plt.show()

在这里插入图片描述 可见,图中三个能量最高的峰值点,正对应时域函数 f ( t ) = s i n ( t ) + 2 s i n ( 3 t ) + 2 c o s ( 2 t ) + 4 s i n ( 15 t ) f(t) = sin(t) + 2sin(3t) + 2cos(2t) + 4sin(15t) f(t)=sin(t)+2sin(3t)+2cos(2t)+4sin(15t) 中合成的三个谐波频率,且能量也和各谐波函数取模后的比例保持一致。

关注
打赏
1660750074
查看更多评论
立即登录/注册

微信扫码登录

0.0403s