Why do I Receive this error? Requested 708198x708198 (3736.8GB) array exceeds maximum array size preference (15.9GB). This might cause MATLAB to become unresponsive.
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, i'm trying to implement a function that simulates the effects of a Leslie Speaker. It actually does its job, but when I call it in the main environment (where I should also compute MSE), I get this error: Requested 708198x708198 (3736.8GB) array exceeds maximum array size preference (15.9GB). This might cause MATLAB to become unresponsive.
The problem is surely in my implementation of the Leslie function, as it's mandatory not to change the main script. Where is the issue? How can I solve it?
Here's the function:
function [y, y_lpf, y_hpf, y_hp_sdf] = leslie(x, Fs, freq)
% Length of the input signal
N = length(x);
% Global modulator parameters
alpha = 0.9;
% Tremble spectral delay filter parameter
Ms_t = 0.2;
Mb_t = -0.75;
N_sdf_t = 4;
% Bass spectral delay filter parameter
Ms_b = 0.04;
Mb_b = -0.92;
N_sdf_b = 3;
% Cross-over network design
fc = 800; % Cutoff frequency
% Compute the coefficients for the two 4th order Butterworth filters
[b_lp, a_lp] = butter(4, fc/(Fs/2), 'low'); % LPF design
[b_hp, a_hp] = butter(4, fc/(Fs/2), 'high'); % HPF design
% Allocate input and output buffers for IIR filters
% HP filter buffers
hpf.state = zeros(max(length(b_hp),length(a_hp))-1, 1);
hpf.in = zeros(max(length(b_hp),length(a_hp))-1, 1);
% LP filter buffers
lpf.state = zeros(max(length(b_lp),length(a_lp))-1, 1);
lpf.in = zeros(max(length(b_lp),length(a_lp))-1, 1);
% Treble SDF filter buffers
sdf_h.state = zeros(N_sdf_t, 1);
sdf_h.in = zeros(N_sdf_t, 1);
% Bass SDF filter buffers
sdf_b.state = zeros(N_sdf_b, 1);
sdf_b.in = zeros(N_sdf_b, 1);
% Modulators
m_b = Ms_b * sin(2*pi*freq*(0:N-1)/Fs) + Mb_b; % Bass modulator
m_t = Ms_t * sin(2*pi*(freq+0.1)*(0:N-1)/Fs) + Mb_t; % Tremble modulator
% Sample processing
y = zeros(N, 1);
y_lpf = zeros(N, 1);
y_hpf = zeros(N, 1);
y_hp_sdf = zeros(N, 1);
for n = 1:N
% Compute crossover network filters outputs
y_lpf(n) = filter(b_lp, a_lp, x(n)) - lpf.in(1);
y_hpf(n) = filter(b_hp, a_hp, x(n)) - hpf.in(1);
% Compute bass SDF output
y_lp_sdf(n) = (1 + m_b(n)) * (y_lpf(n) - sdf_b.in(N_sdf_b));
% Compute treble SDF output
y_hp_sdf(n) = (1 + m_t(n)) * (y_hpf(n) - sdf_h.in(N_sdf_t));
% Implement AM modulation blocks
y_lp_am = (1 + alpha * m_b(n)) * y_lpf(n);
y_hp_am = (1 + alpha * m_t(n)) * y_hpf(n);
y(n) = y_lp_am + y_hp_am; % Output sample
end
end
Here's the main script:
%------------------------------------------%
% *** SSSP - HOMEWORK #3 *** %
%------------------------------------------%
% Emulation of the Leslie Speaker %
%------------------------------------------%
% Name: Gian Marco Ricci / Adriane Replogle %
% Student ID: 10660246 / 10646402 %
%------------------------------------------%
clear; close all; clc;
%% modulation speed
mod_speed = 'tremolo';
%% Read the input file
[x, Fs] = audioread('HammondRef.wav');
x=x(:,1); % take left channel only
%% FX parameters
switch lower(mod_speed)
case {'chorale'}
freq=2;
case {'tremolo'}
freq=6;
otherwise
error('mod_speed \"%s\" not found.', mod_speed)
end
%% Apply FX
y = leslie(x, Fs, freq);
%% Avoid any (possible) clipping
y = rescale(y,-1.,1.);
%% Playback
%audiowrite([mod_speed,'.wav'], y, Fs);
soundsc(y, Fs)
%% Read the reference audio file
dir_name = 'Leslie_ref';
addpath(dir_name);
[y_ref, ~] = audioread(fullfile(dir_name, strcat(mod_speed,'.wav')));
%% Display the MSE
MSE = mean(abs(y.'-y_ref).^2);
MSE_str = sprintf('MSE: %g', MSE);
disp(MSE_str)
0 Kommentare
Antworten (1)
chicken vector
am 15 Jun. 2023
The error message is self-explanatory. Your implementation might be correct but at some point you are generating a variable of size 708198x708198 that occupies mroe than 3 TB of space, which is ay over Matlab's limit (15.9GB), as specified by the error.
You need to restructure our data to decrease the size of you variable.
If you share more details about your code such as the input files and at what line the error happens it would be much easier to help you.
5 Kommentare
chicken vector
am 15 Jun. 2023
When you do:
mean(abs(y.'-y_ref).^2);
you are transposing the first vector so the difference:
y.'-y_ref
is a matrix, rather than a vector, as you can tell from the example below:
ones(3,1) - ones(1,3)
If this was intended you have no other option that to change your code because you have a matrix of 49x10^10 elements and these are too much to handle.
Otherwise do:
y - y_ref
Siehe auch
Kategorien
Mehr zu Filter Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!