You can also do this with an asymmetrical RC filter, if you differentiate the square wave first,
i.e. put it thru a series RC ( or just C ) with an R to gnd, this gives a spike for every edge, then:
through a fast signal diode and an R to charge up a cap, C2, and a larger R across the cap, C2 to more slowly discharge C2, you can then post filter this with a smaller RC filter if you wish - not always necessary,
as the freq goes up the impulses per second to the filter go up giving a higher ave o/p voltage.