加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sin_signal.py 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
tuanergou 提交于 2024-04-05 11:45 . project initialization
# -*- coding: utf-8 -*-
import numpy as np
class SinSignalx(object):
"""docstring for SinSignalx
Parameters
----------
freq : the frequency of the signal
signal_amp: the amplitude of the signal
noise_amp:the amplitude of the noise
"""
def __init__(self,freq,signal_amp,noise_amp):
super(SinSignalx, self).__init__()
self.sn = 128 #sample number
t = np.linspace(0, 1, self.sn, endpoint=False)
u = np.sin(2*np.pi*freq*t)*signal_amp
n = np.random.rand(self.sn)*noise_amp
self.s = u+n
self.pointer = 0
def __add__(self, o):
self.s = self.s+o.s
return self
def get_data_points(self,n):
next_idx = self.pointer+n
if next_idx>=self.sn:
remainder_n = next_idx - self.sn
tmp = self.s[self.pointer:]
tmp2 = self.s[:remainder_n]
self.pointer=remainder_n
return np.concatenate((tmp,tmp2),axis=0)
else:
tmp = self.s[self.pointer:next_idx]
self.pointer=next_idx
return tmp
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化