Arrays have incompatible sizes for this operation.

5 visualizzazioni (ultimi 30 giorni)
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 Commenti
Mohamed Turkmani
Mohamed Turkmani il 29 Ago 2022
how can i make the number of sample the same in each wav file?
Mohamed Turkmani
Mohamed Turkmani il 29 Ago 2022
what is the solution so i can mix both files

Accedi per commentare.

Risposta accettata

Mathieu NOE
Mathieu NOE il 29 Ago 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 Commenti
Mohamed Turkmani
Mohamed Turkmani il 2 Set 2022
i tried it by the way it works but the audio at the end repeats for couple of seconds
Mathieu NOE
Mathieu NOE il 2 Set 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

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by