Putting Stereo in Mono Acoustic Signal

21 views (last 30 days)
I have the following piece of Matlab code trying to do a rough estimate for putting stereo signals into a mono signal.
%Putting in Mono
z1 = (y1(:,1)+y1(:,2))/2;
z2 = (y2(:,1)+y2(:,2))/2;
z3 = (y3(:,1)+y3(:,2))/2;
However, some of my values contain zeros, and I do not want to average a row if it has a zero; I would want to add these.
Only if there are two nonzero values would I want to average. How would I write this?
I apologize, I am very new to Matlab.

Accepted Answer

Star Strider
Star Strider on 8 Dec 2015
One approach:
stereo = randi([0 8], 15, 2); % Signal
lv = ~sum(stereo == 0, 2); % Rows Without Zeros (Logical Vector)
mono = sum(stereo, 2); % Sum Across Columns
mono(lv) = mono(lv)/2; % Divide Rows Without Zeros By ‘2’ To Get Mean

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!