程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Using Python to calculate the transfer function of microphone array signal

編輯:Python

Use python Write a test microphone array transfer function demo, Take what you need . This code uses a third-party library ThinkDSP.

1. Transfer function

First, let's explain what a transfer function is :

The relationship between input and output of objects with linear characteristics , Use a function ( Ratio of Laplace transform of output waveform to Laplace transform of input waveform ) To represent the , Called transfer function .

In microphone array test , The input and output of the transfer function usually refer to the standard test signal and the signal received by each microphone . In the audio signal , The transfer function usually refers to the frequency domain , Therefore, it is necessary to perform Fourier transform on the time-domain signal (FFT).

2. python Transfer function in

stay scipy There is a function class in the library signal, There's a function TransferFunction, This function can be used to calculate the transfer function between two variables .

Please refer to the following official explanations for specific usage :

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.TransferFunction.html

3. python Realization

Required libraries :

import thinkdsp
import wave
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

Ideas :

Generate two chirp The signal s1 and s2, hold s1 As an input signal , hold s2 As if from some mic Obtained output signal . The two signals differ only in amplitude ,s2 The amplitude of is s1 Of 2 times . So according to the signal , Transfer function = Output / Input , The transfer function value of each frequency band should be 2.

First step , Generate two signals . Signal frequency range 100Hz~8kHz, Sampling rate 16kHz. The matrix elements after Fourier transform are in complex form , The transfer function calculation needs to take the real part .

s1 = thinkdsp.ExpoChirp(100,8000,1) # The amplitude is 1
wav1 = s1.make_wave(1,0,16000)
w1 = wav1.make_spectrum()
fs = w1.fs
hs1 = w1.amps
​
s2 = thinkdsp.ExpoChirp(100,8000,2) # The amplitude is 2
wav2 = s2.make_wave(1,0,16000)
w2 = wav2.make_spectrum()
hs2 = w2.amps

The second step , Calculate the transfer function .

s12 = signal.TransferFunction(hs2,hs1)
plt.figure('TransferFunction')
plt.plot(fs,s12.num/s12.den)
plt.ylim(0,3)
plt.show()
print('finish')

Generate the image , Of the entire frequency range 「 Output / Input 」 The transfer function values are 2, Meet preset .

Be careful , Transfer functions are not simple Output / Input , The signal processing has been done in the function TransferFunction Finish in , You can do your own research in the reference documents .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved