MATLAB: How to deliver a sound tone to only one ear

audiosignal processing

Hi everyone;
I am trying to set an experiment on MATLAB where I am going to be producing a tone and sending it to the user via ear plugs. However, the tone coming to the right ear has to be 180degrees out of phase to the tone coming to the left ear.
So for instance, if the frequency is 1000Hz, I will send the 1000Hz signal to the right ear now then wait 0.5ms to send the same tone to the left ear. Hence the two sounds are going to be out of phase with each other.
So my question is: how to tell MatLab to send a tone to only the right ear then send another tone to the other ear. Or how to disable either the left or right earplug.
Thank you for your help. Ali

Best Answer

You can simply add zeros in the silent channel:
t = linspace(0, 5, 22500*5);
y = sin(t * 1000 * 2 * pi);
silence = zeros(1, floor(0.5e-3 * 22500)); % 0.5 ms
signal = [y, silence; silence, y(:)].';
wavplay(signal, 22050);
% Draw the signal to check the phase shift:
plot(signal(1:100, :))