필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
A
A 2017년 5월 7일
답변: Farhamand Khan 2019년 1월 8일
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 ?

답변 (2개)

Star Strider
Star Strider 2017년 5월 7일
‘... 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 2019년 1월 8일
try this way
N=min([ nx ny]);
it will work.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by