I created a white noise signal. I am trying to use the array I have created with the white noise to play in 2 channels. When the left channel I was trying to have 5000 samples and the right will have 0 and when in the right channel it will have 5000 samples and the left will be 0(which means no sound from this channel). I keep getting an error when trying to concatenate the sounds and I think I messed up with the loop because every time it loops it will do 5000 samples and I only need 5000 total with a 10000 sample pause in between the 2 sounds. I also had trouble writing the band-pass filter into the code but it worked when using the FDAToool. Any help would be appreciated.

fs = 44.1; %Sample Frequency khz
L=5000; %Sample length for the random signal  
P=10000; %Sample Pause Gap

Left_signal = [sigma*randn(L,1)+mu 0];
Right_signal = [0 sigma*randn(L,1)+mu];

%Loop thru all samples
for num = 2:L,
%t = num *(1/Fs);
Left_signal = [Left_signal; sigma*randn(L,1)+mu 0];

Pause = zeros(P,2);

for num2 = 2:L,
%t = num2 * (1/Fs);
Right_signal = [Right_signal; 0 sigma*randn(L,1)+mu];

Long_signal = [Left_signal; Pause; Right_signal];
  • $\begingroup$ I'm quite confused by your question. My interpretation of what you want: sound from left channel only (5000 samples), 10.000 samples pause, sound from right channel only (5000 samples). Is that it? $\endgroup$
    – Matt L.
    May 26, 2014 at 7:23
  • $\begingroup$ Yes @Matt L. But I need the opposite channel to be silent so while the left would have 5000 active sounds the right will be silent with 5000 zeros $\endgroup$
    – Asau7610
    May 26, 2014 at 12:09
  • $\begingroup$ I understand. Please check my answer below. $\endgroup$
    – Matt L.
    May 26, 2014 at 12:17

1 Answer 1


If I understand the question correctly this should solve your problem:

L = 5000;
P = 10000;
sigma = 2;
mu = 0;

left = sigma*randn(L,1) + mu;
right = sigma*randn(L,1) + mu;

y = [left zeros(L,1); zeros(P,2); zeros(L,1) right];    % stereo sound matrix

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.