Arrays have incompatible sizes for this operation.

5 vues (au cours des 30 derniers jours)
Mohamed Turkmani
Mohamed Turkmani le 29 Août 2022
Commenté : Mathieu NOE le 2 Sep 2022
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 commentaires
Mohamed Turkmani
Mohamed Turkmani le 29 Août 2022
how can i make the number of sample the same in each wav file?
Mohamed Turkmani
Mohamed Turkmani le 29 Août 2022
what is the solution so i can mix both files

Connectez-vous pour commenter.

Réponse acceptée

Mathieu NOE
Mathieu NOE le 29 Août 2022
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 commentaires
Mohamed Turkmani
Mohamed Turkmani le 2 Sep 2022
i tried it by the way it works but the audio at the end repeats for couple of seconds
Mathieu NOE
Mathieu NOE le 2 Sep 2022
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

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by