mirror of https://github.com/drowe67/phasenn.git
debugging plot_n0.py/est_n0 C code
parent
56abe1afd2
commit
9ab6a221dc
|
@ -26,7 +26,7 @@ def read(filename):
|
|||
# Determine number of records in file, not very Pythonic I know :-)
|
||||
|
||||
nb_samples = 0
|
||||
with open('/home/david/codec2/build_linux/hts1a.model', 'rb') as f:
|
||||
with open(filename, 'rb') as f:
|
||||
while True:
|
||||
try:
|
||||
model = codec2_model.parse_stream(f)
|
||||
|
@ -43,7 +43,7 @@ def read(filename):
|
|||
|
||||
# Read Codec 2 model records into numpy arrays for further work
|
||||
|
||||
with open('/home/david/codec2/build_linux/hts1a.model', 'rb') as f:
|
||||
with open(filename, 'rb') as f:
|
||||
for i in range(nb_samples):
|
||||
model = codec2_model.parse_stream(f)
|
||||
Wo[i] = model.Wo
|
||||
|
|
27
plot_n0.py
27
plot_n0.py
|
@ -6,6 +6,18 @@
|
|||
# Plot n0 estimates on top of speech waveforms for a few test frames
|
||||
# to see if n0 estimation is working.
|
||||
|
||||
'''
|
||||
Usage:
|
||||
~codec/build_linux$ ./misc/timpulse 1 | ./src/c2sim - --modelout imp.model
|
||||
~codec/build_linux$ ./misc/timpulse 1 | ./src/c2sim - --modelout - | ./misc/est_n0 > imp_n0.txt
|
||||
~phasenn$ ./plot_n0.py ~/codec2/build_linux/imp.model ~/codec2/build_linux/imp_n0.txt
|
||||
|
||||
Green line (phase_n0_removed) should be flat, as the phase of an
|
||||
impluse train is comprised of just a linear time shift component, and 0
|
||||
dispersive component.
|
||||
|
||||
'''
|
||||
|
||||
import numpy as np
|
||||
import sys
|
||||
import matplotlib.pyplot as plt
|
||||
|
@ -29,8 +41,14 @@ print("removing linear phase component....")
|
|||
phase_n0_removed = np.zeros((nb_samples, width))
|
||||
for i in range(nb_samples):
|
||||
for m in range(1,L[i]+1):
|
||||
a = n0_est[i]*Wo[i]*m
|
||||
phase_n0_removed[i,m] = np.angle(np.exp(1j*a))
|
||||
phase_n0_removed[i,m] = phase[i,m] - n0_est[i]*Wo[i]*m
|
||||
phase_n0_removed[i,m] = np.angle(np.exp(1j*phase_n0_removed[i,m]))
|
||||
|
||||
f=10
|
||||
print("frame: %d Fo: %f L: %d" % (f,Fs*Wo[f]/(2*np.pi),L[f]))
|
||||
print(A[f,1:L[f]])
|
||||
print(phase[f,1:L[f]])
|
||||
print(phase_n0_removed[f,1:L[f]])
|
||||
|
||||
# TODO: some how choose random set up vectors to plot. Want them above a certain level, and mix of V and UV
|
||||
frame = range(20,32)
|
||||
|
@ -59,10 +77,11 @@ if plot_en:
|
|||
for r in range(12):
|
||||
plt.subplot(3,4,r+1)
|
||||
f = frame[r];
|
||||
plt.plot(phase_n0_removed[f,1:L[f]]*180/np.pi,'r')
|
||||
plt.plot(phase[f,1:L[f]]*180/np.pi,'g')
|
||||
plt.plot(phase_n0_removed[f,1:L[f]]*180/np.pi,'r')
|
||||
plt.ylim(-180,180)
|
||||
plt.show(block=False)
|
||||
print("Green: input phase Red: phase with n0 removed (should be zero)")
|
||||
|
||||
plt.figure(3)
|
||||
plt.title('Time Domain')
|
||||
|
@ -71,7 +90,7 @@ if plot_en:
|
|||
f = frame[r];
|
||||
s = sample_time(f)
|
||||
plt.plot(s,'g')
|
||||
mx = np.max(s)
|
||||
mx = np.max(np.abs(s))
|
||||
plt.plot([n0_est[f],n0_est[f]], [-mx/2,mx/2],'b')
|
||||
plt.show(block=False)
|
||||
|
||||
|
|
Loading…
Reference in New Issue