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

前面的知识这里就不介绍了,下面是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)
中合成的三个谐波频率,且能量也和各谐波函数取模后的比例保持一致。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值