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

조회 수: 5 (최근 30일)
Muhsin Zerey
Muhsin Zerey 2024년 9월 6일
댓글: Muhsin Zerey 2024년 9월 9일
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

채택된 답변

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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

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?

댓글을 달려면 로그인하십시오.

카테고리

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