Azzera filtri
Azzera filtri

How I can add two sound waves with different sampling frequency and dimensions ?

4 visualizzazioni (ultimi 30 giorni)
Dear , As described in the title , I have two sound wave and I want combine them together . One of them has Fs=16 KHz and 1-D ,while the other have has Fs=604 Khz and 2-D . I tried to do this code :
x=audioread('X.wav');
y=audioread('Y.mp3');
nx=length(x);
ny=length(y);
N=min(nx,ny);
A=x(1:N);
B=y(1:N);
signal=A+B;
sound(signal,16000,16);
but I have error : Error using + Matrix dimensions must agree :( any body can help me please ?

Risposte (2)

Star Strider
Star Strider il 7 Mag 2017
‘... has Fs=604 Khz and 2-D’
No worries. The upper limit of normal human hearing is about 20 kHz, so you will never be able to hear it.
I believe you intend 1-column and 2-column, not 1D and 2D.
If the ‘Fs’ value is a typographical error and it is in the range of human hearing, you have to interpolate one of them to the sampling frequency of the other with the Signal Processing Toolbox resample function in order to combine them element-wise (addition, subtraction, multiplication, division). Then, simply shorten the longer record to the length of the shorter record to add them. (Signals with different sampling frequencies can be added, but the result is meaningless. It is best not to do it.)
To use the resample function easily, use the rat function to get the ‘p’ and ‘q’ integers:
[q,r] = rat(Fs1/Fs2);
Then, use the bsxfun function to add the 1-channel signal to the 2-channel signal:
signal = bsxfun(@plus, x, y);
The ‘signal’ variable will be a 2-channel signal.
See the documentation on the various functions to understand how to use them.

Farhamand Khan
Farhamand Khan il 8 Gen 2019
try this way
N=min([ nx ny]);
it will work.

Community Treasure Hunt

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

Start Hunting!

Translated by