数组太大,无法在 matlab 中划分,但不能在 python 中划分



我遇到的问题是 Matlab 中的数组太大。数组数据来自音频文件。我想得到脉冲响应。

我首先FFT原始和录制的音频。然后按原件记录的划分。最后反向FFT以获得脉冲响应。这就是我计划做的,但我被困在了部门部分。

坚持使用Matlab,我找到了一个python代码可以很好地做到这一点。我将代码重写到 Matlab 中,问题又回来了。代码不完整,但足以显示问题。

希望得到很多建议和批评。谢谢

计划执行但失败,因此移至下一个代码

[y_sweep,Fs] = audioread('sweep.wav');
[y_rec,Fs] = audioread('edit_rec_sweep_laptop_1.2.wav');
fft_y1 = abs(fft(y_rec(:,1)));
fft_y2 = abs(fft(y_rec(:,2)));
fft_x = abs(fft(y_sweep));
fft_h1 = fft_y1/fft_x;
% fft_h2 = fft_y2/fft_x;
% fft_h = [fft_h1,fft_h2];
% h1 = ifft(fft1_h);

从 python "翻译"代码,但仍然失败,因此来到这里

[a,fs] = audioread('sweep.wav'); % sweep
[b,fs] = audioread('rec.wav'); % rec
a = pad(a,fs*50,fs*10);
b = pad(b,fs*50,fs*10);
[m,n] = size(b);
h = zeros(m,n); 
for chan = 1:2
b1 = b(:,1);
ffta = abs(fft(a));
fftb = abs(fft(b1));
ffth = fftb / ffta;
end

pad.m 函数(从 Python 翻译而来,但应该是正确的(

function y = pad(data, t_full, t_pre)
[row_dim,col_dim] = size(data);
t_post = t_full - row_dim - t_pre;
if t_post > 0
if col_dim == 1
y = [zeros(t_pre,1);data;zeros(t_post,1)];
%         width = [t_pre,t_post];
else
y1 = [zeros(t_pre,1);data(:,1);zeros(t_post,1)];
y2 = [zeros(t_pre,1);data(:,2);zeros(t_post,1)];
y = [y1,y2];
%         width = [[t_pre,t_post],[0,0]];
end 
else
if col_dim == 1
y = [zeros(t_pre,1);data(t_full - t_pre:end,1)];
%         width = [t_pre,0];
else
y = [zeros(t_pre,1);data(t_full - t_pre:end,1)];
%         width = [[t_pre,0],[0,0]];
end
end
end

错误

Error using   
Requested 4800000x4800000 (171661.4GB) array exceeds
maximum array size preference. Creation of arrays
greater than this limit may take a long time and
cause MATLAB to become unresponsive. See array size
limit or preference panel for more information.
Error in impulseresponse (line 13)
ffth = fftb / ffta;

正斜杠是 MATLAB 中mrdivide()的简写。这是用于求解线性矩阵方程组。我认为你想要的是用./表示的rdivide.

  • c = a/b仅在标量时等效于标准除法b

  • c = a./b是逐元素划分,其中a的每个元素都被相应的元素除以b

    [1 2 3] ./ [2 4 9]
    >> ans = [0.5, 0.5, 0.3333]
    

因此,"计划执行"代码的最后一行变为

fft_h1 = fft_y1 ./ fft_x;

最新更新