signals addition

조회 수: 8 (최근 30일)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012년 5월 3일
답변: Sk Group 2021년 2월 8일
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일
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
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일
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;

카테고리

Help CenterFile Exchange에서 Signal Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by