How to remove the ripple or artifacts caused by lowpass filter?
Show older comments
Hi, I am in a complex situation, where the lowpass fitering with sharp cutoff freqeuncy is affecting a technique I was developing. The following first code use a fc = 80Hz, to extract the envelop. As shown in the second code, I want to reduce the fc to 15Hz and achieve a smooth envelop.i.e. gradient A' reduces in the second simulation compared to first due to reduction of fc from 80 Hz to 15 Hz.
But, reducing to 15Hz, creates additional ripples and sharp edges and changes the expected envelop, which is a problem for me. So,Is there any other way to escape from these artifacts? I tried reducing the filter order to 1, but butter filtering is not performing well. So I am looking if there is any other way to elminate those added artifacts either by changing the lowpass filteration or by post proceesing the extracted envelop?
clear all;
% close all; clc;
%-------------------------------------------------------------
% System definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-------------------------------------------------------------
fs=8192; % sampling frequency
dt = 1/fs; % sample time
T=3; % duration of the signal
Nt = T*fs; % total number of samples
t = 0:dt:T-dt; % time vector
% Source definition
f0 = 900; % initial angular speed in Hz
fT = 2700; % final angular speed in Hz
finst = linspace(f0,fT,Nt);
phi = 2*pi*cumsum(finst)*dt;
a1 = 45;
b1 = 5000;
c1 = 2;
c2 = 1.5;
d1 = 2+3*1j;
% Definition of envelop
int_phi0 = 3*pi/4;
A = d1+(a1 * exp(-b1 * (t - T/c1).^2 + 1j * int_phi0));
% Definition of source signal
q = A.'.*exp(1j*phi).';
filtorder =6; fc =80;%----------------------------------% fc-cutoff
[bcoeff,acoeff] = butter(filtorder,fc/fs*2);
Afilt = filtfilt(bcoeff,acoeff,q.*exp(-1j*phi).');
% figure()
% freqz(bcoeff,acoeff,[],fs)
figure()
plot(t,q,'k')
hold on
plot(t,abs(Afilt),'r','LineWidth',2)
grid on; box on;
legend('q(t)','A(t)')
xlabel('s')
ylabel('Amp')
title('q(t) and A(t) - filtered')
set(gca,'FontSize',15)
xlim([1.2 1.8])
subplot()
clear all;
% close all; clc;
%-------------------------------------------------------------
% System definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-------------------------------------------------------------
fs=8192; % sampling frequency
dt = 1/fs; % sample time
T=3; % duration of the signal
Nt = T*fs; % total number of samples
t = 0:dt:T-dt; % time vector
% Source definition
f0 = 900; % initial angular speed in Hz
fT = 2700; % final angular speed in Hz
finst = linspace(f0,fT,Nt);
phi = 2*pi*cumsum(finst)*dt;
a1 = 45;
b1 = 5000;
c1 = 2;
c2 = 1.5;
d1 = 2+3*1j;
% Definition of envelop
int_phi0 = 3*pi/4;
A = d1+(a1 * exp(-b1 * (t - T/c1).^2 + 1j * int_phi0));
% Definition of source signal
q = A.'.*exp(1j*phi).';
filtorder =6; fc =15;%----------------------------------% fc-cutoff
[bcoeff,acoeff] = butter(filtorder,fc/fs*2);
Afilt = filtfilt(bcoeff,acoeff,q.*exp(-1j*phi).');
% figure()
% freqz(bcoeff,acoeff,[],fs)
figure()
plot(t,q,'k')
hold on
plot(t,abs(Afilt),'r','LineWidth',2)
grid on; box on;
legend('q(t)','A(t)')
xlabel('s')
ylabel('Amp')
title('q(t) and A(t) - filtered')
set(gca,'FontSize',15)
xlim([1.2 1.8])
Accepted Answer
More Answers (1)
Walter Roberson
on 6 Jul 2023
0 votes
Imagine that you were doing a discrete fourier transform of a square wave. Maybe it looks not bad at a target frequency. But then you try to use it at a higher frequency, and you look carefully at the leading and trailing edges and see ripples. Would decreasing the number of fourier coefficients solve the problem? Obviously not. Would increasing the number of fourier coefficients solve the problem? No -- examine the result at a sufficiently high frequency and you would continue to see ripples at the leading and trailing edges.
Using butter filter has similar problems; it is a discrete reconstruction of an ideal filter shape, and if you use too few coefficients the result is going to look bad. You can increase the filter order to make the ripples less obvious, but you cannot eliminate them with any finite order. The best you can do is reduce the magnitude of the ripple to less than a level that is acceptable to you -- which might require increasing the order (which in turn implies increased delays). buttord might help in the design.
Categories
Find more on Analog Filters in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



