Hi, I have the following code.
x1=wavread('speech.wav'); x2=wavread('speech_noise.wav');
I have to do x2-x1
I am getting the error as Dimension mismatch. How to rectify it?

 採用された回答

Richard Brown
Richard Brown 2012 年 5 月 3 日

0 投票

Assuming they correspond to the same sampling rates, truncate one of them to be of the same length as the smaller one:
n1 = length(x1);
n2 = length(x2);
% Assuming n1 < n2
x2 = x2(1:n1)
Or maybe you want to interpolate
x2 = interp1(1:n2, x2, linspace(1, n2, n1));
Or maybe you want to refer back to your other question: http://www.mathworks.com/matlabcentral/answers/36587-adding-of-signals

4 件のコメント

Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012 年 5 月 3 日
Hi Richard,
It works well. Thanks for your support. I tried the first method of yours. I shall check with the speakers and get back to you.
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012 年 5 月 3 日
Hi Richard,
My code is
x1=wavread('speech.wav');
x2=wavread('speech_noise.wav');
v=x1-x2
x1 is clean voice. x2 is clean+noise.
will i get 'v' as noise signal alone
Richard Brown
Richard Brown 2012 年 5 月 3 日
It depends - is x2 a modified version of x1? And if so, why is it a different size?
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012 年 5 月 3 日
i am speaking inside a room ... x1
i am speaking the same content in a crowd(noises)....x2

サインインしてコメントする。

その他の回答 (1 件)

Sk Group
Sk Group 2021 年 2 月 8 日

0 投票

MATLAB CODE:
function [y n] = sigadd(x1,n1,x2,n2)
if n1(1)< n2(1)
a = n1(1)
x1 = [zeros(1,abs(n1(1)-n2(1))) x1]
else
a = n2(1)
x1 = [zeros(1,abs(n1(1)-n2(1))) x1]
end
if n1(end)>n2(end)
b = n1(end)
x2 = [x2 zeros(1,abs(n1(end)-n2(end)))]
else
b = n2(end)
x2 = [x2 zeros(1,abs(n1(end)-n2(end)))]
end
n = a:b;
y = x1+x2;
MATLAB CODE:
function [y n] = sigadd_another_method(x1,n1,x2,n2)
n = min(min(n1),min(n2)):max(max(n1),max(n2));
y1 = zeros(1,length(n));
y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y = y1+y2;

カテゴリ

ヘルプ センター および File ExchangeFourier Analysis and Filtering についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by