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

时间:2021-06-21 17:37:32

标签: python time-series sine-wave

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

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()

0 个答案:

没有答案