Square wave improved --- now takes arbitrary number of terms.