How can I apply a lowpass filter samplewise in my code?

3 次查看(过去 30 天)
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

回答(2 个)

Drishti
Drishti 2024-9-6
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.
  1 个评论
Muhsin Zerey
Muhsin Zerey 2024-9-7
编辑:Muhsin Zerey 2024-9-7
Hi Thanks very much for your help! Do you know how I can apply a butterworth first order as a lowpass filter?

请先登录,再进行评论。


Image Analyst
Image Analyst 2024-9-8
One way is movmean.
  3 个评论
Image Analyst
Image Analyst 2024-9-8
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.
Muhsin Zerey
Muhsin Zerey 2024-9-9
How can I apply it to my code tho? I will need the previous and future next sample to maake an average.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by