Muhsin Zerey asked . 2024-03-09

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

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?
 

lowpass filtering , feedback , delay network , Signal Processing , Audio Toolbox

Expert Answer

Kshitij Singh answered . 2024-12-21 00:22:02

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

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.