如何生成带噪声的随机正弦波?

问题描述

我想用高斯噪声生成正弦波,并将生成的波形数据保存为数据集。 在下一步中,我想找到波形的频率。这是我的代码(但我不知道为什么代码不起作用)?

import numpy as np
import scipy as sy
import scipy.fftpack as syfp
import pylab as pyl
import matplotlib.pyplot as plt
import pandas as pd
import sys
import math
import scipy.stats as stats
import serial

dt = 0.03071 
t = dt*np.arange(100000)             ## time at the same spacing of your data
u = np.sin(2*np.pi*t*.01)   
df= pd.dataframe(u,columns=['data'])
np.random.seed(0)
ds = np.random.randn(1000)
rd = [0]
for i in ds:
    rd.append( np.sin(i*0.7 )+ i)
df = pd.DataFrame(rd,columns=['data'])
# Do FFT analysis of array
FFT = sy.fft(u)

# Getting the related frequencies
freqs = syfp.fftfreq(len(u),dt)     ## added dt,so x-axis is in meaningful units

# Create subplot windows and show plot
pyl.subplot(211)
pyl.plot(t,u)
pyl.xlabel('Time')
pyl.ylabel('Amplitude')
pyl.subplot(212)
pyl.plot(freqs,sy.log10(abs(FFT)),'.')  ## it's important to have the abs here
pyl.xlim(-.05,.05)                       ## zoom into see what's going on at the peak
pyl.show()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)