I am trying to store the signal I have created in a single variable and graph the signal in two subplots in one single graph, one for left channel, one for right channel.

Fs = 44100;
N = 400
t = (1:N)*(1/Fs);
freq = 500;

sound_array = zeros(N,2);
%starts N x 2 matrix
sound_array(:,1) = sin(2*pi*freq*t);
sound_array(:,2) = sin(2*pi*freq*t);

%Left and Right channels
sound_L = sound_array;
sound_L(:,2) = 0;
sound_R = sound_array;
sound_R(:,1) = 0;  

R = 400;
beep = [sound_array; zeros(R, 2)];

%Sound 1 
sound(sound_L, Fs);
%Sound 2
sound(sound_R, Fs);
%Play Consecutive
sound(sound_array, Fs);
  • $\begingroup$ look at 'help plot' and 'help subplot' $\endgroup$ – porten May 16 '14 at 19:33
  • $\begingroup$ oh ok i understand now the part for plotting but how do I store the signal in a single varible @porten $\endgroup$ – Asau7610 May 16 '14 at 19:39
  • $\begingroup$ @Asau7610: I am starting to have a feeling that you are not making any progress on your own. Why won't you try to type into google and play a little bit with MATLAB? It's the easiest programming language ever! $\endgroup$ – jojek May 16 '14 at 19:43
  • $\begingroup$ I learned the image processing side of matlab just recently for a class so just the whole sound thing is giving me issues for this project since making us learn it on the fly. $\endgroup$ – Asau7610 May 16 '14 at 19:53

I suggest you to do something like (one plot with two curves):

plot(sound_L(:,1), 'b'); % blue
hold on; grid on; % prevent from redrawing and add grid\
plot(sound_R(:,2), 'r'); % red
legend({'left', 'right'});

Or if you want two subplots:

plot(sound_L(:,1), 'b'); grid on;
plot(sound_R(:,2), 'r'); grid on;

Please mind that in your case sound_L and sound_R are the same. You are not making any use of beep variable.

|improve this answer|||||
  • $\begingroup$ I thought I had used the beep variable and called @jojek $\endgroup$ – Asau7610 May 16 '14 at 19:53
  • $\begingroup$ @Asau7610: I think that you need to look at your code and really understand what do you want to do with it. Listen to the results, play with it and then you will move forward. $\endgroup$ – jojek May 16 '14 at 19:56
  • $\begingroup$ yea im looking at it now trying to make sure and use the beep varible @jojek $\endgroup$ – Asau7610 May 16 '14 at 20:03
  • $\begingroup$ Since you made the beep varible for the R wouldn't I have to make one for the L too by doing the same thing @jojek ' L = 400;' ' beep = [sound_array; zeros(L, 2)];' $\endgroup$ – Asau7610 May 16 '14 at 20:15
  • $\begingroup$ sound_array contains both channels in your case. You must substitute it with sound_L or sound_R- and yes, you must create two separate variables (although there is plenty of different valid ways to do what) $\endgroup$ – jojek May 16 '14 at 20:20

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.