The first thing that come to mind is to implement a filter with the same even components of frequency and amplitudes of a decomposed square wave (namely, Taylor's series), which may have been supposedly what you did, but it is not clear until which multiple of the fundamental your IIR filter have considered, and you did not show the graph with the result of the filtering that you did. In addition you did not mention the frequency of the carrier, wich should be also considered on the filtering as well.