question about dely lines

조회 수: 4 (최근 30일)
Muhsin Zerey
Muhsin Zerey 2024년 12월 1일
댓글: Muhsin Zerey 2025년 1월 14일
EDITED:
Hey guys, I want to implement an allpass filter but i struggle with the difference equation and its implementation:
heres the structure
and here are the difference equations:
So finally I got the difference equation. I also tried to implemend it into my process function. (d(n) is a delay line in my code before i wanted to implemt the allpass, therefore I commented it out, but can be useful to compare). m(k) and m'(k) are both delays that are calculated. zeta is set to be one and is therefore not in the equation. The plugin sounds wrong and horrible if I try this way. Anyone got an Idea?
function out = process(plugin, in)
out = zeros(size(in));
for i = 1:size(in,1)
% Summieren der L/R - Kanle
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
% plugin.y_a = 0;
% d_n = gain * delayed v_n
for k=1:plugin.N
% if k == 2 && mod(plugin.pBuffDelayLines,2) == 0
% plugin.gy(k) = 0;
%
% end
plugin.Dg(k) = sqrt(1-plugin.g(k)^2);
%plugin.d(k) = plugin.g(k)*plugin.buffDelayLines(k, mod(plugin.pBuffDelayLines + plugin.m(k), plugin.maxDelay +1) + 1);
% d(k) = (((sqrt(1-plugin.g(k)^2)^2)+ plugin.g(k)^2 + plugin.g(k)^2) * x1_m0p) + (plugin.g(k) * x1_m0) - (plugin.g(k) * y_m0p);
x1_m0p = plugin.buffDelayLines(k, mod(plugin.pBuffDelayLines + plugin.m(k)+plugin.m'(k)+1, plugin.maxDelay +1) + 1);
x1_m1p =plugin.buffDelayLines(k, mod(plugin.pBuffDelayLines+ plugin.m(k) +1, plugin.maxDelay +1) + 1);
plugin.d(k)= (plugin.Dg(k)^2+plugin.g(k)^2)*x1_m0p + plugin.g(k)*x1_m1p- plugin.g(k)*plugin.y_a(k);
plugin.y_a(k) = plugin.d(k);
end
%generate time variant matrix
%generateTIFDNmatrix(plugin,buffA);
% 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); %An pe delay noch arbeiten
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
Paul
Paul 2024년 12월 25일
편집: Paul 2024년 12월 25일
Are g_0, D_g0, and zeta_0 all constants? Is delta^m0 an integer?
The input to the filter is x_1(n) and the output is y_1(n) ?
Muhsin Zerey
Muhsin Zerey 2025년 1월 13일
Hi, yes they are all constants. I also already have the difference euqation correctly. Should be like this.

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

답변 (2개)

Walter Roberson
Walter Roberson 2024년 12월 1일
you cannot implement those equations.
e(n) is defined in terms of d(n)
d(n) is defined in terms of e(n - something)
Substituting, e(n) is defined in terms of e(n - something)
This is infinite recursion, and so has no solution.
  댓글 수: 8
Walter Roberson
Walter Roberson 2025년 1월 14일
You need to initialize y(1) through y(dm0_prime)
Muhsin Zerey
Muhsin Zerey 2025년 1월 14일
Everything is done with ring buffers. so the buffer delay line is a ring buffer and in the process function you save all the values of v(n) into the buffer delay line. So d(n) as well as y(n) is depented on v(n) and v(n) is pre delay + the outcome of the mixing matrix*d(n)

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


Paul
Paul 2024년 12월 26일
One can attack this symbolically if the parameters in the problems aren't known. If they are, one can proceed numerically using the Control System Toolbox. Example of the latter
Define the constants, assume a 4 sample delay
g_0 = 0.5;
D_g0 = sqrt(3)/2;
zeta_0 = 1;
delta_m0 = 4;
Define the lti objects for the three equations
sys1 = ss([g_0,D_g0*zeta_0],'Ts',-1,'InputDelay',[delta_m0,0],'InputName',{'x1','d'},'OutputName','y1');
sys2 = ss([zeta_0*D_g0,-g_0],'Ts',-1,'InputDelay',[delta_m0,0],'InputName',{'x1','d'},OutputName = 'e');
sys3 = ss(1,'Ts',-1,'InputDelay',delta_m0,'InputName','e','OutputName','d');
Connect all together
sys = connect(sys1,sys2,sys3,'x1',{'y1','e','d'});
With the selected constants, the system from x1 to y1 is allpass
opts = bodeoptions;
opts.MagUnits = 'abs';
bodeplot(sys(1,1),opts);
Plot the outputs with an input for x1
N = 50;
x1 = [ones(N/2,1);-ones(N/2,1)];
[z,k] = lsim(sys,x1);
y1 = z(:,1);e = z(:,2); d = z(:,3);
figure
hold on
stem(k,y1,'DisplayName','y1');
stem(k,e ,'DisplayName','e');
stem(k,d ,'DisplayName','d');
legend
Check that the outputs satisfy the original difference equations.
x1s = @(n) interp1(k,x1,n,'linear',0);
es = @(n) interp1(k,e, n,'linear',0);
ds = @(n) interp1(k,d, n,'linear',0);
[norm(y1 - ( g_0*x1s(k-delta_m0) + D_g0*zeta_0*ds(k) ));
norm(e - ( D_g0*zeta_0*x1s(k-delta_m0) - g_0*ds(k) ));
norm(d - es(k-delta_m0))]
ans = 3×1
1.0e-15 * 0.3168 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  댓글 수: 1
Muhsin Zerey
Muhsin Zerey 2025년 1월 13일
Hi Paul, I reedited my question and hope you can understand my problem better.

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

카테고리

Help CenterFile Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by