フィルターのクリア

for loop summation problem

1 回表示 (過去 30 日間)
Abbass Ibrahim
Abbass Ibrahim 2022 年 6 月 10 日
回答済み: Mathieu NOE 2022 年 6 月 10 日
i want to add my signals in a for loop , i want to add my values in a for loop so that the a(i)=a(i-1)+b(i)

回答 (1 件)

Mathieu NOE
Mathieu NOE 2022 年 6 月 10 日
hello
please clarify what is a and b in your request. Usually those letters are used for numerator (B) and denominator (A) of an IIR digital filter.
see example below : a and b are coefficients of IIR filter (fixed), x is the input data and y is the output
you can adapt this example to your specific needs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% data
[x,Fs] = audioread('test_voice_mono.wav');
[samples,channels] = size(x);
dt = 1/Fs;
time = (0:samples-1)*dt;
%% IIR filter recursive equation
c1 = 8;
c2 = 2;
c3 = 7;
b0 = 0.05 * c1;
b1 = 0.03 * c2;
b2 = 0.02 * c3;
a1 = 0.5;
a2 = 0.5;
% manual for loop coding IIR filter
y(1) = b0*x(1) + 0 + 0 + 0 + 0; % 1st iteration
y(2) = b0*x(2) + b1*x(1) + 0 + a1*y(1) + 0; % 2nd iteration
for k = 3:samples % for iteration # 3 and after
y(k) = b0*x(k) + b1*x(k-1) + b2*x(k-2) + a1*y(k-1) + a2*y(k-2);
end
figure(1)
plot(time,x,time,y)

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by