# why does butterworth IIR filter for a square pulse show ripple on edges in time domain but not the same for sine wave

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
offset=0;
amp=3.3;
duty=50;
t=0:0.01:100;%100 seconds
sq_wav=offset+amp*square(2*pi*fs.*t,duty);
sin_wav = offset + amp*sin(2*pi*fs.*t);
disp(length(sin_wav));

N = length(sq_wav);
disp(N);
#disp(t(1:10));
t1 = [0:N-1];
disp(t1(1:10));
disp(fs);
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)
plot(t(1:end),sq_wav(1:end))
title("square pulse");

subplot (4, 1, 2)
plot(t(1:end),sin_wav(1:end))
title("sine pulse");

subplot (4, 1, 3)
plot(t(1:end),out_sq(1:end))
title("square pluse after butterworth");

subplot (4, 1, 4)
plot(t(1:end),out_sin(1:end))
title("sine pluse after butterworth");



Here is the output of this code: