# Plotting the difference in magnitude and phase between two signals using specgram

I have two synthesised audio signals that I've convolved with impulse responses from a multi-channel microphone and I'm wanting to plot the difference in phase and magnitude using matplotlib's specgram(). The test signal I'm using is a unit impulse generated by scipy.unit_impulse().

As the two signals (due to the convolution) have been captured on a single microphone array with capsules/sensors all very close to each other I would expect minimal (but still some) differences in magnitude and some differences in phase that are frequency dependent.

At present, I'm using the below code, however, the results (to me) don't seem quite right. The individual magnitude plots seem similar (which is fine and to be expected) but when I plot the difference, this seems to have similar values as the two original signals. I would have expected there to be much smaller differences.

With the phase plots I'll be honest that I'm not really sure what I'm looking at, and I'm not sure whether the phase differences are meaningful, or just noise.

Also - the magnitude plummets after 1 second as that's roughly how long it takes for the impulse response of the system to decay. This is also confusing as I would expect the absolute difference after that point to also be pretty small. Unless of course, I'm misunderstanding something fundamental about how differences are presented when using dB scales.

My main questions are, am I plotting my data correctly, but just misunderstanding the resulting plots, or have I done something stupid when calculating the absolute difference.

import matplotlib.pyplot as plt

diff = abs(sig1 - sig2)

# PLOTS FOR MAGNITUDE

fig, ((ax1, ax2, ax3)) = plt.subplots(3,1, sharex=True)
fig.text(0.44,0.95,'Magnitude plots', ha='center', size='x-large')
fig.text(0.5,0.04, 'Time in seconds', ha='center' )
fig.text(0.04, 0.5, 'Frequency in Hz', va='center', rotation='vertical')

pxx1, freq1, t1, cax1 = ax1.specgram(sig1, mode='psd', NFFT=256, Fs=48000, scale='dB')
ax1.set_title('Left Channel')
ax1.set_xlim([0,1.5])

ax2.set_title('Right Channel')
pxx2, freq2, t2, cax2 = ax2.specgram(sig2, mode='psd', NFFT=256, Fs=48000, scale='dB')
ax2.set_xlim([0,1.5])

ax3.set_title('abs diff')
pxx3, freq3, t3, cax3 = ax3.specgram(diff, mode='psd', NFFT=256, Fs = 48000, scale='dB')
ax3.set_xlim([0,1.5])

fig.colorbar(cax1, ax=ax1)
fig.colorbar(cax2, ax=ax2)
fig.colorbar(cax3, ax=ax3)

# PLOTS FOR PHASE

fig2, ((ax4, ax5, ax6)) = plt.subplots(3,1, sharex=True)
fig2.text(0.44,0.95,'Phase plots', ha='center', size='x-large')
fig2.text(0.5,0.04, 'Time in seconds', ha='center' )
fig2.text(0.04, 0.5, 'Phase in Radians?', va='center', rotation='vertical')

pxx4, freq4, t4, cax4 = ax4.specgram(sig1, mode='phase', NFFT=256, Fs=48000, scale='linear')
ax4.set_title('Left Channel')

ax5.set_title('Right Channel')
pxx5, freq5, t5, cax5 = ax5.specgram(sig2, mode='phase', NFFT=256, Fs=48000, scale='linear')

ax6.set_title('abs diff')
pxx6, freq6, t6, cax6 = ax6.specgram(diff, mode='phase', NFFT=256, Fs = 48000, scale='linear')
fig2.colorbar(cax1, ax=ax4)
fig2.colorbar(cax2, ax=ax5)
fig2.colorbar(cax3, ax=ax6)
ax4.set_xlim(0,1.5)