Skip to content

Commit

Permalink
Clean up of names and cvxpy dependency. Added placeholder folder for …
Browse files Browse the repository at this point in the history
…figures and sound_samples.
  • Loading branch information
fakufaku committed Jul 15, 2014
1 parent 77267ed commit a594a6d
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 54 deletions.
43 changes: 0 additions & 43 deletions beamforming.py
@@ -1,5 +1,4 @@
import numpy as np
import cvxpy as cp
from time import sleep

import constants
Expand Down Expand Up @@ -36,48 +35,6 @@ def mdot(*args):
return ret


def complex_to_real_matrix(A):

A_real = np.real(A)
A_imag = np.imag(A)

A_ctr = np.vstack([np.hstack([A_real, -A_imag]),
np.hstack([A_imag, A_real])])

return A_ctr


def real_to_complex_vector(b):

n = b.shape[0] / 2
return b[0:n] + 1j * b[n:]


def echo_beamformer_cvx(A_good, A_bad):

# Expand complex matrices and vectors to real matrices and vectors
A_good_ctr_H = complex_to_real_matrix(H(A_good))
A_bad_ctr_H = complex_to_real_matrix(H(A_bad))

M = A_good.shape[0]
K = A_good.shape[1]

h = cp.Variable(2 * M)

# Objective: minimize(norm(h.H * A_good)^2)

objective = cp.Minimize(cp.sum_entries(cp.square(A_bad_ctr_H * h)))

# Constraint: sum(h.H * A_good) = 1 + 0*1j
constraints = [cp.sum_entries((A_good_ctr_H * h)[0:K]) == 1,
cp.sum_entries((A_good_ctr_H * h)[K:]) == 0]

problem = cp.Problem(objective, constraints)
problem.solve()

return np.array(real_to_complex_vector(h.value))


def distance(X, Y):
# Assume X, Y are arrays, *not* matrices
X = np.array(X)
Expand Down
8 changes: 4 additions & 4 deletions figure_Measures1.py
Expand Up @@ -194,8 +194,8 @@

plt.legend(beamformer_names, fontsize=7, loc='upper left', frameon=False, labelspacing=0)

plt.savefig('SINR_vs_K.png')
plt.savefig('SINR_vs_K.pdf')
plt.savefig('figures/SINR_vs_K.png')
plt.savefig('figures/SINR_vs_K.pdf')

plt.close()

Expand Down Expand Up @@ -253,5 +253,5 @@

plt.legend(beamformer_names, fontsize=7, loc='upper left', frameon=False, labelspacing=0)

plt.savefig('UDR_vs_K.png')
plt.savefig('UDR_vs_K.pdf')
plt.savefig('figures/UDR_vs_K.png')
plt.savefig('figures/UDR_vs_K.pdf')
4 changes: 2 additions & 2 deletions figure_Measures2.py
Expand Up @@ -161,8 +161,8 @@

plt.legend(beamformer_names, fontsize=7, loc='lower right', frameon=False, labelspacing=0)

plt.savefig('SINR_vs_freq.png')
plt.savefig('SINR_vs_freq.pdf')
plt.savefig('figures/SINR_vs_freq.png')
plt.savefig('figures/SINR_vs_freq.pdf')



4 changes: 2 additions & 2 deletions figure_SumNorm.py
Expand Up @@ -109,6 +109,6 @@
plt.ylabel('SNR gain [dB]', fontsize=10)
plt.tight_layout()

plt.savefig('SNR_gain.png')
plt.savefig('SNR_gain.pdf')
plt.savefig('figures/SNR_gain.png')
plt.savefig('figures/SNR_gain.pdf')

File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions fig_spectrograms.py → figure_spectrograms.py
Expand Up @@ -163,9 +163,9 @@
output_maxsinr = output_maxsinr[:n_lim]

# save all files for listening test
wavfile.write('input_mic.wav', Fs, input_mic)
wavfile.write('output_mvdr.wav', Fs, output_mvdr)
wavfile.write('output_maxsinr.wav', Fs, output_maxsinr)
wavfile.write('output_samples/input_mic.wav', Fs, input_mic)
wavfile.write('output_samples/output_mvdr.wav', Fs, output_mvdr)
wavfile.write('output_samples/output_maxsinr.wav', Fs, output_maxsinr)

# compute time-frequency planes
F0 = stft(input_clean, fft_size, fft_hop,
Expand Down
1 change: 1 addition & 0 deletions figures/README.md
@@ -0,0 +1 @@
A directory to store all generated figures.
1 change: 1 addition & 0 deletions output_samples/README.md
@@ -0,0 +1 @@
A directory to store all generated output sound samples.

0 comments on commit a594a6d

Please sign in to comment.