signals addition
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sivakumaran Chandrasekaran
am 3 Mai 2012
Beantwortet: Sk Group
am 8 Feb. 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?
0 Kommentare
Akzeptierte Antwort
Richard Brown
am 3 Mai 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 Kommentare
Richard Brown
am 3 Mai 2012
It depends - is x2 a modified version of x1? And if so, why is it a different size?
Weitere Antworten (1)
Sk Group
am 8 Feb. 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;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Signal Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!