Digital state variable filter.

Algorithm development and general DSP issues

Moderator: frank

Post Reply
sad1024
Posts: 34
Joined: Mon May 24, 2010 3:34 pm

Digital state variable filter.

Post by sad1024 »

equ HP reg0
equ BP reg1
equ LP reg2
equ K1 reg3

sof 0,0
ldax pot0
sof 0.8, 0.1
wrax K1, 1
sof 0,0

ldax adcl
rdax LP, 1
rdax BP, 1
wrax HP, 1
wrhx HP, K1
wrax BP, 1
wrhx BP, K1
wrax LP, 1
ldax BP
wrax adcl, 1

Can anyone tell me why this does not work?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

"wrhx" requires an immediate value, not a register.
Frank Thomson
Experimental Noize
sad1024
Posts: 34
Joined: Mon May 24, 2010 3:34 pm

Post by sad1024 »

equ HP reg0
equ BP reg1
equ LP reg2

ldax adcl
rdax LP, -1
rdax BP, -1
wrax HP, 1
sof 0,0
wrhx HP, 0.1
wrax BP, 1
sof 0,0
wrhx BP, 0.1
wrax LP, 1
sof 0,0
ldax BP
wrax dacl, 1

I am trying to use wrhx as an attenuator followed by an integrator. Can this be done? The program doesn't work so far.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Please comment code, makes it much easier to help when we know your intent at each step.
Frank Thomson
Experimental Noize
sad1024
Posts: 34
Joined: Mon May 24, 2010 3:34 pm

Post by sad1024 »

equ HP reg0
equ BP reg1 ; setup registry locations for high pass, low pass, etc.
equ LP reg2

ldax adcl ;read input
rdax LP, -1 ;low pass feedback
rdax BP, -1 ;band pass feedback
wrax HP, 1 ;write high pass to reg.
sof 0,0 ;clear accumulator
wrhx HP, 0.1 ;read high pass, attenuate by 10th, integrate?
wrax BP, 1 ;write band pass to reg.
sof 0,0 ;clear accumulator
wrhx BP, 0.1 ;read band pass, attenuate by 10th, integrate?
wrax LP, 1 ;write low pass to reg.
sof 0,0 ;clear accumulator
ldax BP ;recall band pass from reg.
wrax dacl, 1 ;write to output
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

wrhx HP, 0.1 ;read high pass, attenuate by 10th, integrate?
and
wrhx BP, 0.1 ;read band pass, attenuate by 10th, integrate?

'wrhx' are write commands, not read so you are writing to the registers, not reading from them as your comments indicate.

Also, the sof before the first wrhx cleared the accumulator so what are you trying to integrate? PACC?
Frank Thomson
Experimental Noize
sad1024
Posts: 34
Joined: Mon May 24, 2010 3:34 pm

Post by sad1024 »

equ HP reg0
equ BP reg1
equ LP reg2

sof 0,0
ldax adcl
rdax LP, -1
rdax BP, -1
wrhx HP, 0.1 Write high pass to HP, multiply acc by 0.1 and integrate.
wrhx BP, 0.1 Write band pass to BP, multiply acc by 0.1 and integrate.
wrax LP, 0 Write low pass to LP, acc x 0
ldax HP
wrax dacl, 1

I am trying to write a program for a state variable filter as concisely as possible. The above program does not work. I'm stumped.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Try the following:

Code: Select all

equ HP reg0
equ BP reg1
equ LP reg2

sof 0,0
ldax adcl ; read ADCL
rdax LP, -1 ; -LP
rdax BP, -1 ; -BP
wrax HP, 0.1 ; Write high pass to HP, multiply acc by 0.1
rdax BP, 1.0 ; add BP
wrax BP, 0.1 ; Write band pass to BP, multiply acc by 0.1.
rdax LP, 1.0 ; add LP
wrax LP, 0 ; Write low pass to LP, acc x 0
ldax HP ; read HP to ACC
wrax dacl, 0 ; write to left and clear ACC
ldax LP ; read LP to ACC
wrax dacr, 0 ; write ro right anc clear ACC
Frank Thomson
Experimental Noize
sad1024
Posts: 34
Joined: Mon May 24, 2010 3:34 pm

Post by sad1024 »

Thanks! Here is a variation of that code that might be useful.


equ HP reg0
equ BP reg1
equ LP reg2
equ out0 reg3
equ out1 reg4

sof 0,0
ldax adcl ; read ADCL
rdax LP, -1 ; -LP
rdax BP, -1 ; -BP
wrax HP, 0.1 ; Write high pass to HP, multiply acc by 0.1
rdax BP, 1.0 ; add BP
wrax BP, 0.01 ; Write band pass to BP, multiply acc by 0.1.
rdax LP, 1.0 ; add LP
wrax LP, 0 ; Write low pass to LP, acc x 0
ldax LP ; Read LP, put in acc.
mulx pot0 ; multiply by pot0
wrax out0, 0 ;write to out0, clear acc.
ldax BP ; read BP, put in acc.
mulx pot1 ; multiply by pot1
wrax out1, 0 ; write to out1, clear acc.
ldax HP ; read HP, put in acc.
mulx pot2 ; multiply by pot2
rdax out0, 1 ; plus out0
rdax out1, 1 ; plus out1
wrax dacl, 0 ; write to dacl, clear acc.

This gives you a 3 band eq that seems to work?
Post Reply