Very well xnor! I stand corrected about that filter! I didn't go all the way and devil is always in the details . Any how, IIR filters are relatively small compared to their FIR counter parts. However, they don't always play nice in the phase. And phase matters!

Here is a more elaborate piece of code you can run (select between Butterworth, Chebyshev, and Hamming windowed FIR).

**Code**

% clean slate

close all;

clear all;

% main parameter

sim.highpass.select = 2; % 0: chebyshev / 1: butterworth / 2: fir1 (Hamming)

% parameters

sim.N = 5000; % number of samples

sim.fs = 44.1e3; % sampling rate (Hz)

sim.sw.f = 300; % square wave fundamental (Hz)

sim.highpass.iir_order = 5; % filter order (iir)

sim.highpass.fir_order = 500; % filter order (fir)

sim.highpass.cutoff = 200; % filter cutoff

sim.highpass.ripple = 0.5; % filter ripple (if applicable)

% derived parameters

% square wave

sim.sw.time = (0:sim.N-1)/sim.fs;

sim.sw.data = 2*((cos(2*pi*sim.sw.time*sim.sw.f))>0)-1;

% plot square wave excitation

figure(1)

plot(sim.sw.time,sim.sw.data);

grid on;

axis tight;

xlabel('time (s)');

ylabel('au');

title('Input square wave');

% filter

switch sim.highpass.select

case 0,

[sim.highpass.B, sim.highpass.A]=cheby1(sim.highpass.iir_order, ...

sim.highpass.ripple,sim.highpass.cutoff/sim.fs, 'high');

case 1,

[sim.highpass.B, sim.highpass.A]=butter(sim.highpass.iir_order, ...

sim.highpass.cutoff/sim.fs, 'high');

otherwise,

sim.highpass.A = 1;

sim.highpass.B=fir1(sim.highpass.fir_order, ...

sim.highpass.cutoff/sim.fs, 'high');

end

[sim.highpass.H, sim.highpass.F]=freqz(sim.highpass.B,sim.highpass.A,1024,sim.fs);

% plot filter responce

figure(2);

subplot 211;

semilogx(sim.highpass.F,20*log10(abs(sim.highpass.H)));

grid on;

axis tight;

xlabel('Hz');

ylabel('Magnitude');

subplot 212;

semilogx(sim.highpass.F,angle(sim.highpass.H));

grid on;

axis tight;

xlabel('Hz');

ylabel('Phase');

% pass it through filter

sim.sw.output = filter(sim.highpass.B, sim.highpass.A, sim.sw.data);

% plot results

figure(3);

plot(sim.sw.time,sim.sw.output);

grid on;

axis tight;

xlabel('time (s)');

ylabel('au');

title('Output square wave');

FIRs don't have that many issues with phase and are stable at the expense of size. Also, due to the size, there will be quite a bit of group delay there. Here are the results:

**Butterworth 5th order**

**Chevyshev 5th order**

**FIR1 (Hamming) 500 length:**

Enjoy