加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
PHYS613 A10 Exercise6.10 FFT.py 1022 Bytes
一键复制 编辑 原始数据 按行查看 历史
Nick Crump 提交于 2015-10-14 20:32 . computational physics
"""
Created on Mon Nov 11 10:15:15 2013
PHYS 613, Assignment 10
Nick Crump
"""
# Exercise 6.10
"""
Consider signals periodic in time and analyze sampling rates
using FFT to determine transformed freq spectrum of signal.
"""
import numpy as np
import FFTspectrum as fft
import matplotlib.pyplot as plt
# define freq to sample signal
sfreq = 128 # Hz
Ttot = 5 # sec
dt = 1.0/sfreq
# define time points and signal values
t = np.arange(0,Ttot+dt,dt)
f = np.cos(6*np.pi*t)
# call FFT from my module to get freq spectrum
fs,spectrum = fft.FFTspectrum(t,f,sfreq)
# print max freq found in spectrum
mx = max(spectrum)
indx = np.where(spectrum==mx)[0]
print '\n','max freq =',round(fs[indx],2)
# plot time domain signal
plt.subplot(211)
plt.plot(t,f)
plt.xlabel('Time (sec)')
plt.ylabel('Amplitude')
# plot freq domain signal
plt.subplot(212)
plt.plot(fs,spectrum, label='$128\ Hz\ sample$' +'\n' '$\ \ \ \ 3\ Hz\ freq$')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Normalized Magnitude')
plt.xlim(0,20)
plt.legend()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化