Arrays have incompatible sizes for this operation.

조회 수: 5 (최근 30일)
Mohamed Turkmani
Mohamed Turkmani 2022년 8월 29일
댓글: Mathieu NOE 2022년 9월 2일
i have the following code which mixes two audios as the user enters the number he wants to mix
freq = str2double(get(handles.edit3,'string'));
scnd = str2double (get(handles.edit10,'string'));
[y,Fs] = audioread("Sound and "+freq+" hz.wav");
[x,Fs] = audioread(scnd+".wav");
mix = y+x;
soundsc(mix,sample);
Nsamps = length(mix);
t = (1/Fs)*(1:Nsamps);
y_fft = abs(fft(mix));
y_fft = y_fft(1:Nsamps/2);
f = Fs*(0:Nsamps/2-1)/Nsamps;
axes(handles.axes3);
plot(f, y_fft)
xlim([0 5000])
ylim([0 5000])
end
some values seem to work while others dont and i get Arrays have incompatible sizes for this operation.
  댓글 수: 3
Mohamed Turkmani
Mohamed Turkmani 2022년 8월 29일
how can i make the number of sample the same in each wav file?
Mohamed Turkmani
Mohamed Turkmani 2022년 8월 29일
what is the solution so i can mix both files

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 8월 29일
hello
in case the two files have different number of samples, either you truncate the longest one or you padd the shortest one (with zeros);
I opted for the second solution :
freq = str2double(get(handles.edit3,'string'));
scnd = str2double (get(handles.edit10,'string'));
[y,Fs] = audioread("Sound and "+freq+" hz.wav");
[x,Fs] = audioread(scnd+".wav");
%%
x = x(:); % make x col vector
y = y(:); % make y col vector
lx = numel(x);
ly = numel(y);
if ly>lx
x = [x; zeros(ly-lx,1)];
elseif ly<lx
y = [y; zeros(lx-ly,1)];
end
%%
mix = y+x;
% soundsc(mix,sample); % ?? 2nd argument should be Fs ?
soundsc(mix,Fs); % please double check 2nd argument
Nsamps = length(mix);
t = (1/Fs)*(1:Nsamps);
y_fft = abs(fft(mix));
y_fft = y_fft(1:Nsamps/2);
f = Fs*(0:Nsamps/2-1)/Nsamps;
axes(handles.axes3);
plot(f, y_fft)
xlim([0 5000])
ylim([0 5000])
  댓글 수: 2
Mohamed Turkmani
Mohamed Turkmani 2022년 9월 2일
i tried it by the way it works but the audio at the end repeats for couple of seconds
Mathieu NOE
Mathieu NOE 2022년 9월 2일
hmm
I wonder if your files have one or more channels , so what are dimensions of x and y just after your read them
[y,Fs] = audioread("Sound and "+freq+" hz.wav");
[x,Fs] = audioread(scnd+".wav");
maybe your "echoes" are related to these lines I introduced , have to change that for multi channel audio (if that is the case) :
x = x(:); % make x col vector
y = y(:); % make y col vector

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by