Clipping

When clipping a signal, we use a clipping threshold and hold the output signal at the clipping level if the input signal exceeds this level. The signal is unmodified below the clipping threshold. This technique is often referred to as "hard clipping".

Signal Flow

Audio signal graphs

A Sine wave
Clipping

Sound examples


440 Hz Sine wave, clean

440 Hz Sine wave, hard clipped at a threshold of 0.9

440 Hz Sine wave, hard clipped at a threshold of 0.6

440 Hz Sine wave, hard clipped at a threshold of 0.3


Csound code

The following Csound code generates a sine wave and processes it by hard clipping. The clipping threshold is set as a fraction of full level, so a threshold of 0.5 clips at 50% of full signal level. The output amplitude is adjusted with the use of makeup gain, so the output amplitude shouuld equal the input amplitude regardless of clipping threshold.

;***************************************************
; Hard clip
;***************************************************
	instr	1

	iamp		= ampdbfs(p4)	; Amp in -dB
	icps		= p5		; Frequency for the tone generator
	iClip		= p6		; Clipping threshold 
					; (as fraction of full level, e.g. 0.5 clips at 50%)
	iMakeupGain	= 1/iClip	; Make up for gain loss in clipping stage

; audio generator
	a1		oscili	1, icps, giSine

; hard clip
	a1		limit	a1, -iClip, iClip	; hard clipping

; output gain
	a1		= a1*iamp*iMakeupGain

; audio out
	out		a1

	endin
;***************************************************