Array too big for division in matlab but not python -


the problem have array big in matlab. array data comes audio file. want impulse response.

i first fft original , recorded audio. division of recorded original. lastly inverse fft impulse response. planned got stuck @ division part.

stuck using matlab, found python code can fine. rewrite code matlab , problem again. code incomplete enough show problem.

hope many advice , criticism. thanks

planned failed moved on next code

[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); 

'translated' code python still failed came here

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

pad.m function (translated python should correct)

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

error using  \  requested 4800000x4800000 (171661.4gb) array exceeds maximum array size preference. creation of arrays greater limit may take long time , cause matlab become unresponsive. see array size limit or preference panel more information.  error in impulseresponse (line 13)     ffth = fftb / ffta; 

the forward slash shorthand in matlab mrdivide(). this solving systems of linear matrix equations. think want rdivide denoted ./.

  • c = a/b equivalent standard division if b scalar.

  • c = a./b element-wise division, every element of a divided corresponding element of b.

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

so last active line of "planned do" code becomes

fft_h1 = fft_y1 ./ fft_x; 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -