combine 2 audio sounds together

2 views (last 30 days)
Eyal Ronen
Eyal Ronen on 26 Feb 2023
Answered: Image Analyst on 26 Feb 2023
I have two audio files with the same length and sample rate. I would like to sum these two signals together to create a new signal: sum[n] = audio1[n] + audio2[n]*(-1)^n.
I would like to know how to implement these operations using MATLAB.
thank!

Answers (1)

Image Analyst
Image Analyst on 26 Feb 2023
The sum may exceed the range for a sound but might be ok if you use soundsc. But I'd use mean
Don't use "sum" as the name of your variable since that is a very important function that you'll no longer be able to use if you do that.
theSum = mean([audio1; audio2]);
If you want you can transform audio2 like
weights = (-1) .^ (1:n)
audio2 = audio2 .* weights;
before you do the sum

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!