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
0 个评论
回答(2 个)
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.
Image Analyst
2024-9-8
3 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!