Csound Csound-dev Csound-tekno Search About

Re: harmonic oscillator blues

Date1998-04-02 19:44
Fromkhalid
SubjectRe: harmonic oscillator blues
Richard Dobson wrote:
> 
> I remember reading a posting on the comp.dsp newsgroup about this sort of
> problem, recommending that the gain be made ~very~ slightly greater than unity,
> and the output is clipped. Might that work here?

	I haven't tried but to get what one would expect from the
undamped harm. oscillator you may use a damped one (F-zv+kx=0) and
set z=k. Surprisingly(?) this works cleanly and exact.
The below orc/sco demonstrates this.

kd
;--------------start orc--------------------------
sr=44100
kr=44100
ksmps=1
nchnls=1

        instr   1
; harm. oscillator without damper
; F+kx=0 => M(v(n)-v(n-1))=-kx => x(n)-2x(n-1)+x(n-2)=-k/Mx(n) =>
; (1+k/M)x(n)=2x(n-1)-x(n-2) => x(n)=(M/M+k)(2x(n-1)-x(n-2))

im      init    10
ik      init    .01
ie      init    500     ; spring elongation at x(0)
ic      init    im/(im+ik)
ax0     init    0
ax1     init    0
ax2     init    -ie/ic  ; make x(0) = if

ax0     =       ic*(2*ax1-ax2)
        out     ax0
ax2     =       ax1
ax1     =       ax0

        endin

        instr 2
; harm. osc with damper
; F-zv+kx=0 => x(n)-2x(n-1)+x(n-2)=z/M(x(n)-x(n-1))-k/Mx(n) =>
; (1-z/M+k/M)x(n)=((M-z+k)/M)x(n)=(2-z/M)x(n-1)-x(n-2) =>
; x(n)=(M/(M-z+k))((2-z/M)x(n-1)-x(n-2))

im      init    10
ik      init    .01
iz      init    ik - p4 ; p4 actually damps (if positive)
ie      init    500     ; spring elongation at x(0)
ic1     init    im/(im-iz+ik)
ic2     init    2-iz/im
ax0     init    0
ax1     init    0
ax2     init    -ie/ic1 ; make x(0) = if

ax0     =       ic1*(ic2*ax1-ax2)
        out     ax0
ax2     =       ax1
ax1     =       ax0

        endin

;----------start score-------------------------------
i1 0 2
i2 2 2 .001
i2 4 2 0