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

Microphone array signal test: phase test (Python)

編輯:Python

For microphone arrays ,N Whether there is a delay between microphones , Can pass N The phase difference between data . Phase difference is one of the important indicators to judge the synchronization of microphone signal .

1. Phase and phase difference

First, explain what is phase and phase difference .

1.1 phase

phase (phase) It's for a wave , The position of a particular moment in its cycle : Whether it's on the crest 、 The scale of a trough or a point between them .

Phase describes the measurement of signal waveform change , Usually, the degree ( angle ) As a unit , Also called phase angle . When the signal waveform changes periodically , The waveform circulates for one cycle 360° .

for example : In function y=Acos(ωx+φ) in ,ωx+φ be called phase .

1.2 Phase difference

Phase difference : The difference between the phases of two physical quantities that change periodically with the same frequency is called the phase difference , Or difference .

Phase difference in simple harmonic motion : If the frequencies of two simple harmonic motions are equal , The initial phases are φ1,φ2. When φ2>φ1 when , Their phase difference is :

△φ=(ωt+φ2)-(ωt+φ1)=φ2-φ1

At this time we often say 2 Phase ratio of 1 leading △φ.

2. python seek MIC Array phase difference

The following mainly talks about how to use python Find the phase difference between microphone array signals . Take two signals for example , Suppose the two signals are data obtained from two microphone signals .

2.1 Realize the idea

The signal in the recorded audio is a time domain signal , It needs to be transformed into frequency domain signal by Fourier transform , The data after Fourier transform is complex , The real part is the amplitude , The imaginary part represents the phase . The most important step in phase calculation is Unwinding .

Specific explanation of unwinding , Please refer to the following link :
https://blog.csdn.net/bpssy/article/details/22218589

2.2 Python Realization

Libraries to be called :

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

Set the sampling rate and duration :

framerate = 16000
time = 1

Generate two signals , The phase difference between the two signals is 10°:

# Generation duration 1 Second sampling rate 16kHz Of 100Hz - 8kHz Frequency sweep signal 
t = np.arange(0, time, 1.0/framerate)
wave_data = signal.chirp(t, 100, time, 8000, method='linear')
wave_data2 = signal.chirp(t, 100, time, 8000, method='linear',phi = 10)

Carry out Fourier transform , Time domain variable frequency domain :

data1 = np.fft.rfft(wave_data)/len(wave_data)
fr = np.fft.rfftfreq(len(wave_data),1/framerate)
sp1 = 20*np.log10(np.abs(data1))
data11 = np.fft.fft(wave_data)
data21 = np.fft.fft(wave_data2)
data111 = np.angle(data11, deg = True)
data211 = np.angle(data21,deg = True)
# Unwind the data unwrap#
data112 = data111/180*np.pi
data113 = np.unwrap(data112)

mapping , Show results :

plt.figure('Phase_delta',figsize=(8,4))
plt.plot((data213[:512]-data113[:512])*180/np.pi,label = 'data213-data113')
plt.ylim(0,50)
plt.legend()
plt.show()

The final result is as follows , The phase difference between the effective frequency intervals of the two signals is 10 degree , In line with expectations .

More articles please pay attention to WeChat official account 「 Smart speaker design 」.


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