signals addition

7 visualizaciones (últimos 30 días)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 3 de Mayo de 2012
Respondida: Sk Group el 8 de Feb. de 2021
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?

Respuesta aceptada

Richard Brown
Richard Brown el 3 de Mayo de 2012
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 comentarios
Richard Brown
Richard Brown el 3 de Mayo de 2012
It depends - is x2 a modified version of x1? And if so, why is it a different size?
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 3 de Mayo de 2012
i am speaking inside a room ... x1
i am speaking the same content in a crowd(noises)....x2

Iniciar sesión para comentar.

Más respuestas (1)

Sk Group
Sk Group el 8 de Feb. de 2021
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;

Categorías

Más información sobre Signal Processing Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by