I am using butterworth filter for both square pulse and sine wave. In case of square pulse, butterworth produces some sharp ripple of edges of square pulse in time domain for varying butterworth order (wn > 2). But in case of sine wave, I don't see any ripple. Could anyone please explain the reason behind that? Matlab code is following along with plots.

close all

clear all
T = 1/10;
t = linspace(0,T,1001);

s = square (2*pi*100*t);

fs=10/200; % sampling frequency
fc=0.2; % fc normalized
t=0:0.01:100;%100 seconds
sin_wav = offset + amp*sin(2*pi*fs.*t);

N = length(sq_wav);
t1 = [0:N-1];
wn = 15; % filter order

[b,a] = butter(wn, fc);

[h,w] = freqz(b,a);

out_sq = filter(b,a,sq_wav);
out_sin = filter(b,a,sin_wav);

subplot (4, 1, 1)
title("square pulse");

subplot (4, 1, 2)
title("sine pulse");

subplot (4, 1, 3)
title("square pluse after butterworth");

subplot (4, 1, 4)
title("sine pluse after butterworth");

Here is the output of this code:

enter image description here


1 Answer 1


This happens because when lowpass filtering, you remove the high-frequency content that gives the square pulses their sharp edges. Now, if you're not yet versed in Fourier analysis of signals this will be a bit tough, but I'll provide some graphs to show what I mean.

Let's take a simple pulse and a sinusoid like the ones you have. We're going to filter them with a simple 4-th order Butterworth filter. Below are the time-domain and frequency-domain plots of the signals. The spectrum of the filter is also included. The spectrum plots are in decibels (dB).

enter image description here enter image description here

If you don't know, filtering in the time domain is multiplication in the frequency domain. So you can look at the frequency spectrums and multiply them together, seeing where the attenuation takes place. You can see that the pulse has more significant contributions from high frequencies compared to the sinusoid. So after filtering, the sinusoid will be less distorted than the pulse which is exactly what we see below

enter image description here

We can take this a step further and remove more frequency content by using a tighter filter. Below are the same spectrums with the new filter. You see that the pulse is now even more distorted, while the sinusoid remains relatively unchanged.

enter image description here enter image description here

  • $\begingroup$ Thanks so much for explaining with the graph. Appreciate it. $\endgroup$ May 22, 2021 at 6:17
  • 1
    $\begingroup$ @ShadekurRahman Note that there are other ways to approach this phenomenon. The Gibbs phenomenon mathematically describes this in time-domain, specifically looking at jump discontinuities, where there is significant frequency content. $\endgroup$
    – Envidia
    May 22, 2021 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.