## 新闻中心

EEPW首页 > 测试测量 > 设计应用 > 敲击扬声器震动信号建模

# 敲击扬声器震动信号建模

#!/usr/local/bin/python

# -*- coding: gbk -*-

#******************************

# TEST1.PY                     -- by Dr. ZhuoQing 2023-03-01

#

# Note:

#******************************

from tsmodule.tsvisa        import *

mso24open()

tspsave('wave1', x=x, y=y)

plt.plot(x, y)

plt.xlabel("Time(s)")

plt.ylabel("Voltage(V)")

plt.grid(True)

plt.tight_layout()

plt.show()

#------------------------------------------------------------

#        END OF FILE : TEST1.PY

#******************************

▲ 图1.2.1 敲击扬声器中间获得的波形

▲ 图1.2.2 50个数据进行平滑之后的波形

▲ 图1.2.3 曲线拟合后的结果

▲ 图1.3.2 信号波形拟合函数以及对应的参数

#!/usr/local/bin/python

# -*- coding: gbk -*-

#******************************

# TEST2.PY                     -- by Dr. ZhuoQing 2023-03-01

#

# Note:

#******************************

from scipy.optimize        import curve_fit

x, y = tspload('wave1', 'x', 'y')

printf(len(x), len(y))

AVERAGE_NUM = 50

DATA_LENGTH = len(x)//AVERAGE_NUM

xx = array([sum(x[i*AVERAGE_NUM:i*AVERAGE_NUM+AVERAGE_NUM])/AVERAGE_NUM*1e3 for i in range(DATA_LENGTH)])

yy = array([sum(y[i*AVERAGE_NUM:i*AVERAGE_NUM+AVERAGE_NUM])/AVERAGE_NUM for i in range(DATA_LENGTH)])

c = where(xx>5)

xxx = xx[c]/1000

yyy = yy[c]

tspsave('wave11', xxx=xxx, yyy=yyy)

#------------------------------------------------------------

'''

plt.plot(xxx, yyy)

plt.xlabel("Time(s)")

plt.ylabel("Voltage(V)")

plt.grid(True)

plt.tight_layout()

plt.show()

'''

#------------------------------------------------------------

def fun(x,a,b,c,d,e):

return a*exp(-b*x)*sin(c*x+d)+e

param = (1, 50, 2*pi*150, 0, 0)

param, conv = curve_fit(fun, xxx, yyy, p0=param)

printf(param)

ysim = fun(xxx, *param)

plt.plot(xxx, yyy, linewidth=3, label='Origin')

plt.plot(xxx, ysim, label='Fit')

plt.xlabel("Time(s)")

plt.ylabel("Voltage(V)")

plt.grid(True)

plt.legend(loc="upper right")

plt.tight_layout()

plt.show()

#------------------------------------------------------------

#        END OF FILE : TEST2.PY

#******************************

import sys, os

sys.path.append(r'd:pythonteasoft')

STDFILE = open(r'd:pythonstd.txt', 'a', 1)

sysstderr = sys.stderr

sysstdout = sys.stdout

sys.stderr = STDFILE

sys.stdout = STDFILE

import time, math, winsound, clipboard, random

from numpy import *

from tsmodule.tspdata   import *

from tsmodule.tspyt     import *

from tsmodule.tscmd     import *

from tsmodule.tsdopop   import *

from tsmodule.tsdraw    import *

import tsmodule.tsconfig

import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']

plt.rcParams['axes.unicode_minus'] = False

plt.figure(figsize=(10,80*10/128))

plt.get_current_fig_manager().window.wm_geometry("+1950+300")

plt.rcParams.update({'font.size':14})