How can I add a low pass filter after each delay line in my multi channel feedback delay network

2 visualizaciones (últimos 30 días)
Im about to program this structure in Matlab in a for loop
So far so good. And I have already done the for loop. I also implemented a Hadamard Mixing Matrix. Here is the code:
in = [ 1; 0 ]; % Dirac Impulse
Fs = 44100;
in = [in; zeros(3*Fs,1)]; % Space for reverb
% Define delay parameters
%Hadamard Matrix as feedback matrix
H = 0.75*hadamard(16);
feedbackGain =[0.1,-0.15,-0.2,0.25,-0.3,0.35,0.4,-0.45,-0.5,0.55,0.6,-0.65,-0.7,-0.75,-0.8,0.85]; %0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85
wetGain = [0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7]; % adjust to control wet signal level
% Convert delay time to samples
delaySamples = [101,233, 439,613, 853,1163, 1453,1667 , 1801,2053, 2269,2647, 3001,3607, 4153,4591]; %0.02s, 0.03, 0.04, 0.05 881, 1009, 1321,1511, 1777, 1999, 2203, 2351
%101, 439, 853, 1453 , 1801, 2269, 3001, 4153
%Summe delays = 30644
% delaySamples = [1200, 1800, 2200,2500];
% Create an empty array to store delayed audio
delayedAudio = zeros(size(in));
delayedAudio2 = zeros(size(in));
delayedAudio3 = zeros(size(in));
delayedAudio4 = zeros(size(in));
delayedAudio5 = zeros(size(in));
delayedAudio6 = zeros(size(in));
delayedAudio7 = zeros(size(in));
delayedAudio8 = zeros(size(in));
delayedAudio9 = zeros(size(in));
delayedAudio10 = zeros(size(in));
delayedAudio11 = zeros(size(in));
delayedAudio12 = zeros(size(in));
delayedAudio13 = zeros(size(in));
delayedAudio14 = zeros(size(in));
delayedAudio15 = zeros(size(in));
delayedAudio16 = zeros(size(in));
delayedAudios =[delayedAudio,delayedAudio2,delayedAudio3,delayedAudio4,delayedAudio5,delayedAudio6,delayedAudio7,delayedAudio8,delayedAudio9,delayedAudio10,delayedAudio11,delayedAudio12,delayedAudio13,delayedAudio14,delayedAudio15,delayedAudio16];
delayedAudios(1,:) = 1;
% Apply delay effect
for i = 1:length(in)-2*max(delaySamples)
for k = 1:16
if delayedAudios(i+delaySamples(k),k) == 0
delayedAudios(i+delaySamples(k),k) = feedbackGain(k)*delayedAudios(i,k);
end
end
for k = 1:16
for j = 1:16
if delayedAudios(i+delaySamples(j)+delaySamples(k),k) == 0 && k~= j
delayedAudios(i+delaySamples(j)+delaySamples(k),k) = H(j,k)*delayedAudios(i+delaySamples(j),j);
end
end
end
end
%Original and Mix together
for k = 1:16
delayedAudios(:,k) = wetGain(k)*delayedAudios(:,k);
end
%outputAudioM = delayedAudios(:,16) + delayedAudios(:,15) + delayedAudios(:,14) + delayedAudios(:,13) + delayedAudios(:,12) +delayedAudios(:,11) +delayedAudios(:,10) +delayedAudios(:,9)+delayedAudios(:,8) +delayedAudios(:,7) +delayedAudios(:,6) +delayedAudios(:,5) +delayedAudios(:,4) +delayedAudios(:,3) +delayedAudios(:,2 )+delayedAudios(:,1);
outputAudioM = sum(delayedAudios,2);
outputAudioM(1) = outputAudioM(1)*0.02;
%Low pass filtering + phase adjusting
d = designfilt('lowpassfir','FilterOrder',4 ,'CutoffFrequency',2000,'SampleRate', Fs);
y = filtfilt(d,outputAudioM);
% %Write the output audio to a new file and plot
audiowrite('output_audio_with_delay.wav', y, Fs);
plot(y);
% Play the output audio
sound(y,Fs);
As you can see in the code I implemented a lpf AFTER the sound was computed. That of course is no problem but I have no idea how I can do that in the for loop like in the picture I showed. Can someone explain how it is to be done or give me hints?

Respuesta aceptada

jibrahim
jibrahim el 27 de Feb. de 2024
Hi Muhsin,
In general, in order to perform filtering and listen to the output inside your for loop, you use filter System objects to perform filtering, and audioDeviceWriter to play the output.
The application you are working with is somewhat similar to a reverberation object that ships with Audio Toolbox: audioexample.FreeverbReverberator. That objects internally uses a bank of allpass filters implemented using dsp.IIRFilter objects.
Here is a simple sample code of how to use the object to filter input data and listen ot the output in the loop.
% Process samples from an audio file
afr = dsp.AudioFileReader("FunkyDrums-44p1-stereo-25secs.mp3",PlayCount=Inf);
% The filter
r = audioexample.FreeverbReverberator;
% Play the result
adw = audioDeviceWriter(SampleRate=afr.SampleRate);
while ~isDone(afr)
x = afr(); % read an input frame
y = r(x); % filter the frame. the filter retains states between consecutive calls
adw(y); % listen ot the output frame
end
  4 comentarios
Muhsin Zerey
Muhsin Zerey el 28 de Feb. de 2024
Editada: Muhsin Zerey el 28 de Feb. de 2024
Thanks for the answer. In my case I have to filter at the same time while I am doing a feedback loop. Also I dont have a finished mp3 file, in my case its a WAV File. When I filter by a low pass filter that value needs to get fed back. Does your code support this?
Sorry for all these questions. Im fairly new to this and there are some things I dont quite understand.
jibrahim
jibrahim el 28 de Feb. de 2024
You are free to do whatever you want in the loop, including feedback. In case you want to read from a wav file instead of an mp3 file, dsp.AudioFileReader supports that.
These examples might be a good introduction to streaming dignal processing:

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Audio Processing Algorithm Design en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by