enhanced waveform drawing algorithm