Artefacts when filtering a contiguous signal

1 次查看(过去 30 天)
Hello,
I have a signal vector vec (54 sampling points). That looks like that:
vec = [5 8 10 8 5 3 1 3 5];
vec = [vec vec vec vec vec vec];
When I filter it with a lowpassfilter, it looks like that (Fig1):
Code for the filtering is:
h = fdesign.lowpass('fp,fst,ap,ast', 0.10, 1, 1, 60);
Hd = design(h, 'equiripple');
c = filter(Hd,vec);
plot(c);
Now, I want to split the sample in zwo sections and filter them separately. As a result, I want to get the same result as in Fig1.
I tried this code:
% design filter
h = fdesign.lowpass('fp,fst,ap,ast', 0.10, 1, 1, 60);
Hd = design(h, 'equiripple');
% split signal in two sections
vec1 = vec(1:27);
vec2 = vec(28:54);
% define numerator, denominator and initial conditions for filter delay
num = Hd.Numerator;
den = 1;
zi = vec1(end-2:end);
% filter the two sections
c1 = filter(num,den,vec1);
c2 = filter(num,den,vec2,zi);
% concatenate and plot the filtered sections
c = [c1 c2];
plot(c);
but get artefacts in the plot:
Could someone tell me what am I doing wrong?
Best regards,
Rocketman

采纳的回答

Jan
Jan 2022-9-15
编辑:Jan 2022-9-15
The final state of the filter parameters after the 1st block is not the value of the signal. Replace:
zi = vec1(end-2:end); % Nope
c1 = filter(num, den, vec1);
c2 = filter(num, den, vec2, zi);
by
[c1, zf] = filter(num, den, vec1);
c2 = filter(num, den, vec2, zf);
There are still tiny differences in the magnitude of 1e-15 caused by rounding, because the implementations differ slightly:
c1 = filter(Hd, vec);
c2 = filter(Hd.Numerator, 1, vec)
plot(c1 - c2)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Signal Generation and Preprocessing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by