How can I apply a lowpass filter samplewise in my code?
9 views (last 30 days)
Show older comments
Muhsin Zerey
on 6 Sep 2024
Commented: Muhsin Zerey
on 9 Sep 2024
I have a real time plugin that does a little bit of reverberation. After each delay line in v(n) I want to apply a lowpass filter to cut out the high frequencies. How can I do that?
My code below:
function out = process(plugin, in)
out = zeros(size(in));
for i = 1:size(in,1)
% Summieren der L/R - Kan�le
inL = in(i,1);
inR = in(i,2);
inSum = (inL + inR)/2;
plugin.buffInput(plugin.pBuffInput + 1) = inSum;
% loop over delay lines
for n=1:plugin.N
% d_n = gain * delayed v_n
for k=1:plugin.N
plugin.d(k) = plugin.g(k) * plugin.buffDelayLines(k, mod(plugin.pBuffDelayLines + plugin.m(k), plugin.maxDelay +1) + 1);
end
% f_n = A(n,:) * d'
plugin.f(n) = plugin.A(n,:) * plugin.d(:);
% v_n with pre delay
plugin.v(n) = plugin.b(n) * plugin.buffInput(mod(plugin.pBuffInput + plugin.preDelayS, (plugin.maxPreDelay * plugin.fs + 1)) + 1) ...
+ plugin.f(n);
plugin.buffDelayLines(n, plugin.pBuffDelayLines + 1) = plugin.v(n);
% output lines
plugin.s(n) = plugin.c(n) * plugin.d(n);
out(i,:) = out(i,:) + real(plugin.s(n));
end
% Assign to output
out(i,1) = plugin.mix/100 * out(i,1) + (1.0 - plugin.mix/100) * in(i,1);
out(i,2) = plugin.mix/100 * out(i,2) + (1.0 - plugin.mix/100) * in(i,2);
calculatePointer(plugin);
end
end
0 Comments
Accepted Answer
Image Analyst
on 8 Sep 2024
3 Comments
Image Analyst
on 8 Sep 2024
You just pass your signal to it. The wider the window, the more samples are included in your average and the smoother the signal will be. Smoothing a signal (replacing elements by the local average) is a low pass filter operation. It's the same thing as convolution or Fourier filtering.
More Answers (1)
Drishti
on 6 Sep 2024
Hi Muhsin,
I understand that you are trying to implement a low pass filter to cut out the high frequencies.
To include the low-pass filter, refer to the implemented code:
% v_n with pre delay
rawVn = plugin.b(n) * plugin.buffInput(mod(plugin.pBuffInput + plugin.preDelayS, (plugin.maxPreDelay * plugin.fs + 1)) + 1) ...
+ plugin.f(n);
% Apply low-pass filter
plugin.v(n) = alpha * rawVn + (1 - alpha) * prevY(n);
prevY(n) = plugin.v(n);
plugin.buffDelayLines(n, plugin.pBuffDelayLines + 1) = plugin.v(n);
To achieve this, I have made certain assumptions which includes ‘cuttoffFreq’ and ‘alpha’ parameters as mentioned below:
% Define the cutoff frequency and calculate alpha
cutoffFreq = 100; % Example cutoff frequency in Hz
alpha = (2 * pi * cutoffFreq) / (plugin.fs + 2 * pi * cutoffFreq);
% Initialize the previous output for the filter
prevY = zeros(plugin.N, 1);
I hope this helps in applying the low pass filter in the provided code.
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!