def blow_up(F, x, y, aspect, ax, zoom=None):
    w = x[1]+1-x[0]
    h = y[1]+1-y[0]
    extent = [0,w,0,h]
    plt.imshow(u.dB(F[x[0]:x[1]+1,y[0]:y[1]+1].T),
            aspect=aspect,
            origin='lower', extent=extent,
            vmin=vmin, vmax=vmax, cmap=cmap, interpolation=interpolation)
    if zoom is not None:
        wo = w*(1-zoom)/zoom
        ho = h*(1-zoom)/zoom
        ax.set_xlim(-wo/2,w+wo/2)
        ax.set_ylim(-ho/2,h+ho/2)
    ax.set_ylabel('')
    ax.set_xlabel('')
    ax.axis('off')
def blow_up(F, x, y, aspect, ax, zoom=None):
    w = x[1] + 1 - x[0]
    h = y[1] + 1 - y[0]
    extent = [0, w, 0, h]
    plt.imshow(u.dB(F[x[0]:x[1] + 1, y[0]:y[1] + 1].T),
               aspect=aspect,
               origin='lower',
               extent=extent,
               vmin=vmin,
               vmax=vmax,
               cmap=cmap,
               interpolation=interpolation)
    if zoom is not None:
        wo = w * (1 - zoom) / zoom
        ho = h * (1 - zoom) / zoom
        ax.set_xlim(-wo / 2, w + wo / 2)
        ax.set_ylim(-ho / 2, h + ho / 2)
    ax.set_ylabel('')
    ax.set_xlabel('')
    ax.axis('off')
opesq_tri = np.zeros((0,2,2))
opesq_bf = np.zeros((0,2,NBF,max_sources))
isinr = np.zeros((0))
osinr_tri = np.zeros((0,2))
osinr_bf = np.zeros((0,NBF,max_sources))

# Read in all the data
for fname in files:
    print 'Loading from',fname

    a = np.load(fname)

    good_source = np.concatenate((good_source, a['good_source']), axis=0)
    bad_source = np.concatenate((bad_source, a['bad_source']), axis=0)

    isinr = np.concatenate((isinr,u.dB(a['isinr'])), axis=0)
    osinr_bf = np.concatenate((osinr_bf,u.dB(a['osinr_bf'])), axis=0)
    osinr_tri = np.concatenate((osinr_tri,u.dB(a['osinr_trinicon'])), axis=0)
    ipesq = np.concatenate((ipesq,a['pesq_input']), axis=0)
    opesq_bf = np.concatenate((opesq_bf,a['pesq_bf']), axis=0)
    opesq_tri = np.concatenate((opesq_tri,a['pesq_trinicon']), axis=0)

loops = good_source.shape[0]

print 'Number of loops:',loops
print 'Median input Raw MOS',np.median(ipesq[:,0])
print 'Median input MOS LQO',np.median(ipesq[:,1])
print 'Median input SINR',np.median(isinr[:])

# Trinicon is blind so we have PESQ for both output channels
# Select the channel that has highest Raw MOS for evaluation
mics.rakeMaxSINRWeights(good_sources, bad_sources, 
                        R_n = sigma2_n*np.eye(mics.M), 
                        rcond=0., 
                        attn=True, ff=False)

output_maxsinr = mics.process()

# high-pass and normalize
output_maxsinr = u.highpass(output_maxsinr, Fs)
output_maxsinr = u.normalize(output_maxsinr)

'''
PLOT SPECTROGRAM
'''

dSNR = u.dB(room1.dSNR(mics.center[:,0], source=0), power=True)
print 'The direct SNR for good source is ' + str(dSNR)

# as comparison pic central mic signal
input_mic = mics.signals[mics.M/2]

# high-pass and normalize
input_mic = u.highpass(input_mic, Fs)
input_mic = u.normalize(input_mic)

# remove a bit of signal at the end and time-align all signals.
# the delays were visually measured by plotting the signals
n_lim = np.ceil(len(input_mic) - t_cut*Fs)
input_clean = signal1[:n_lim]
input_mic = input_mic[105:n_lim+105]
output_mvdr = output_mvdr[31:n_lim+31]
opesq_tri = np.zeros((0, 2, 2))
opesq_bf = np.zeros((0, 2, NBF, max_sources))
isinr = np.zeros((0))
osinr_tri = np.zeros((0, 2))
osinr_bf = np.zeros((0, NBF, max_sources))

# Read in all the data
for fname in files:
    print 'Loading from', fname

    a = np.load(fname)

    good_source = np.concatenate((good_source, a['good_source']), axis=0)
    bad_source = np.concatenate((bad_source, a['bad_source']), axis=0)

    isinr = np.concatenate((isinr, u.dB(a['isinr'])), axis=0)
    osinr_bf = np.concatenate((osinr_bf, u.dB(a['osinr_bf'])), axis=0)
    osinr_tri = np.concatenate((osinr_tri, u.dB(a['osinr_trinicon'])), axis=0)
    ipesq = np.concatenate((ipesq, a['pesq_input']), axis=0)
    opesq_bf = np.concatenate((opesq_bf, a['pesq_bf']), axis=0)
    opesq_tri = np.concatenate((opesq_tri, a['pesq_trinicon']), axis=0)

loops = good_source.shape[0]

print 'Number of loops:', loops
print 'Median input Raw MOS', np.median(ipesq[:, 0])
print 'Median input MOS LQO', np.median(ipesq[:, 1])
print 'Median input SINR', np.median(isinr[:])

# Trinicon is blind so we have PESQ for both output channels
# Select the channel that has highest Raw MOS for evaluation
                        bad_sources,
                        R_n=sigma2_n * np.eye(mics.M),
                        rcond=0.,
                        attn=True,
                        ff=False)

output_maxsinr = mics.process()

# high-pass and normalize
output_maxsinr = u.highpass(output_maxsinr, Fs)
output_maxsinr = u.normalize(output_maxsinr)
'''
PLOT SPECTROGRAM
'''

dSNR = u.dB(room1.dSNR(mics.center[:, 0], source=0), power=True)
print 'The direct SNR for good source is ' + str(dSNR)

# as comparison pic central mic signal
input_mic = mics.signals[mics.M / 2]

# high-pass and normalize
input_mic = u.highpass(input_mic, Fs)
input_mic = u.normalize(input_mic)

# remove a bit of signal at the end and time-align all signals.
# the delays were visually measured by plotting the signals
n_lim = np.ceil(len(input_mic) - t_cut * Fs)
input_clean = signal1[:n_lim]
input_mic = input_mic[105:n_lim + 105]
output_mvdr = output_mvdr[31:n_lim + 31]