Arrays have incompatible sizes for this operation.
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Simulation, Tuning, and Visualization についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!