Bandpass Resonant Filter

Algorithm development and general DSP issues

Moderator: frank

Post Reply
MacroMachines
Posts: 71
Joined: Fri Dec 12, 2014 10:45 pm
Location: Detroit,MI
Contact:

Bandpass Resonant Filter

Post by MacroMachines »

I am wondering how i can streamline this code I got from spinCAD, from the notch module, I just want a 2nd order resonant bandpass and Im sure I don't need nearly this many registers and ops to do it:

Code: Select all

;------ Notch
RDAX POT1,1.0000000000
SOF 0.2000000000,0.0000000000
RDFX REG10,0.0100000000
WRAX REG10,1.0000000000
WRAX REG6,0.0000000000
RDAX REG2,1.0000000000
SOF 1.0000000000,-1.0000000000
ABSA
RDFX REG11,0.0100000000
WRAX REG11,1.0000000000
WRAX REG7,0.0000000000
LDAX REG5
MULX REG6
RDAX REG4,1.0000000000
WRAX REG4,-1.0000000000
RDAX REG1,1.0000000000
WRAX REG8,1.0000000000
LDAX REG5
MULX REG7
SOF 1.4142135624,0.0000000000
SOF -1.4142135624,0.0000000000
RDAX REG8,1.0000000000
WRAX REG8,1.0000000000
MULX REG6
SOF 0.4385941600,0.0000000000
RDAX REG5,1.0000000000
WRAX REG5,0.0000000000
LDAX REG4
RDAX REG8,1.0000000000
WRAX REG9,1.0000000000
I am hoping to make a bank of resonators, I was able to get 3 using spinCAD before running out of registers, it sounds amazing, and I can get a decent physical model going with 8 or so.

I also just made a pretty cool oscillator using spin cad in about 15 minutes! insanity!!!:
https://www.instagram.com/p/BG2FK-thymG ... =axiomcrux
http://MacroMachines.net
Digital Control for your Analog Soul.
MacroMachines
Posts: 71
Joined: Fri Dec 12, 2014 10:45 pm
Location: Detroit,MI
Contact:

Post by MacroMachines »

Here is where I got with it:

Code: Select all

;------ Resonator
equ freq reg2

RDAX POT0, 0.2		;frequency pot
WRAX freq, 0		;stored in reg2 for frequency

RDAX POT1, 0.01
WRAX REG3, 0.		;store reg3 and clear

LDAX REG1		;load reg1
MULX freq		;multiply by freq
RDAX REG0, 1.		;ACC+reg0
WRAX REG0, -1		;write reg0, invert
RDAX ADCL, 1		;add adcl

WRAX REG4, 1		; write reg4
LDAX REG1		;load reg1
MULX REG3		;mult by reg3

SOF -1, 0	 		;times -k
RDAX REG4, 1.		 ;add reg4
WRAX REG4, 1.		;write reg4

MULX REG2		;times reg2

RDAX REG1, 1		;add reg1
WRAX REG1,0		;write reg1 and clear
LDAX REG0		;read reg0



;------ Output
RDAX REG1, 1

WRAX DACL, 1
WRAX DACR, 0
I was able to eliminate quite a bit in streamlining it to a resonator
http://MacroMachines.net
Digital Control for your Analog Soul.
MacroMachines
Posts: 71
Joined: Fri Dec 12, 2014 10:45 pm
Location: Detroit,MI
Contact:

Post by MacroMachines »

a bit more work, are my labels correct? what would reg0 be?

Code: Select all

;------ Resonator

equ freq reg1
equ reso reg2
equ input reg3
equ output reg4


RDAX POT0, 0.2		; frequency pot
WRAX freq, 0		; store frequency and clear

RDAX POT1, 0.01		; resonance pot
WRAX reso, 0.		; store reso and clear

LDAX output		; load output for feedback
MULX freq		; multiply by freq
RDAX REG0, 1.		; ACC+reg0
WRAX REG0, -1		; write reg0, invert
RDAX ADCL, 1		; add adcl
WRAX input, 1		; write input

LDAX output		; load output 
MULX reso 		; mult by resonance
SOF -1, 0	 		; invert
RDAX input, 1.		; add input 
WRAX input, 1.		; write input 
MULX freq		; times frequency 

RDAX output, 1		; add output
WRAX output, 0		; write output and clear


;------ Output
RDAX output, 1

WRAX DACL, 1
WRAX DACR, 0
http://MacroMachines.net
Digital Control for your Analog Soul.
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Someone gave me that code for the notch function, which I threw into SPinCAD Designer without much thought, but I don't think it is very efficient. I have a more recent two-pole state variable filter that should be able to do LP, BP, HP all at the same time. I'll try to remember to post that this evening.
MacroMachines
Posts: 71
Joined: Fri Dec 12, 2014 10:45 pm
Location: Detroit,MI
Contact:

Post by MacroMachines »

Digital Larry wrote:Someone gave me that code for the notch function, which I threw into SPinCAD Designer without much thought, but I don't think it is very efficient. I have a more recent two-pole state variable filter that should be able to do LP, BP, HP all at the same time. I'll try to remember to post that this evening.
Would love to check out your Svf :)
http://MacroMachines.net
Digital Control for your Analog Soul.
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

There's a very useful block diagram.

http://www.earlevel.com/main/2003/03/02 ... le-filter/

Code: Select all

rdax wf1, 1
mulx wf
rdax wf2, 1.0
wrax wf2, -1.0
rdax adcl, 1.0
wrax temp, 0
rdax wf1, -1
mulx wq
rdax temp, 1
wrax hp_out, 1
mulx wf
rdax wf1, 1
wrax wf1, 0 
MacroMachines
Posts: 71
Joined: Fri Dec 12, 2014 10:45 pm
Location: Detroit,MI
Contact:

Post by MacroMachines »

Digital Larry wrote:There's a very useful block diagram.

http://www.earlevel.com/main/2003/03/02 ... le-filter/

Code: Select all

rdax wf1, 1
mulx wf
rdax wf2, 1.0
wrax wf2, -1.0
rdax adcl, 1.0
wrax temp, 0
rdax wf1, -1
mulx wq
rdax temp, 1
wrax hp_out, 1
mulx wf
rdax wf1, 1
wrax wf1, 0 
A couple questions, how do you set the frequency as noted? It uses a sin function, is there a way to do this in asm or is it somehow not needed?
Also, I see the labeled hp_out but where is bp and lp? I could likely trim down a few lines with that info. Cheers and thank you!
http://MacroMachines.net
Digital Control for your Analog Soul.
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

The frequency control comes in on "wf" which is some other variable (register), or possibly a pot put through an SOF statement and stored in a register.

The lp and bp are in wf1 and wf2. My request to you since I'm not currently doing anything with the FV-1 is to try them and report back which is which.

If you don't need hi pass then you can get rid of the hp_out register, however the state variable filter structure does require the rest of this code to be in there even if you are not using the low pass out.

I don't quite catch your comment about the "sin" function, can you elaborate?
Aaron
Posts: 54
Joined: Wed Mar 04, 2015 8:10 pm
Location: Oklahoma

Post by Aaron »

I believe MacroMachines is referring to the function:

f = 2sin(pi*Fc/Fs)

This is what you use to find the coefficient for the corner frequency (wf).
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

My answer to that is that how filters move dynamically with changes in the control input is a fascinating topic unto itself and in the case of something like an auto-wah, can have a significant impact on the evolving sound. But I can't tell you whether linear or log or reverse square root is the best. I can tell you that trying all of those to see which one floats your boat the best can be fun and frustrating.
MacroMachines
Posts: 71
Joined: Fri Dec 12, 2014 10:45 pm
Location: Detroit,MI
Contact:

Post by MacroMachines »

I don't understand why people don't give their variables somewhat readable names. its already alien enough working with 3 letter opcodes, can't variable equs just be "frequency" or "freq" or "lowpass" or even "LP"

jeesh :P

HAHAHAHA did you read the code I posted in the first reply where I edited down your notch bandpass? I just double checked and this is EXACTLY what I already had! boiled it down to!!! HAHAHAHA :P

regarding the sin function, I realized it was not actually important in this context since I am not trying to set the frequency specifically via "440Hz" and am just using potentiometers. I have been doing a lot of tests lately with Audulus3, I am sure I mentioned elsewhere, but in there I can easily use the expression node to make "sin(x)" and z-1 transform node and delay lines and biquads etc.. so I am used to functioning on a slightly more digital modular network mentality and forget sometimes FV-1 is more like making a nice sauce, you just sort of add the ingredients you think will work and pinch in bits of salt and pepper till it tastes good. :P Not that I don't do that in audulus, just that when I am copying an online referenced DSP block diagram I first do it precisely as shown. I replicated the block diagram for this while I was camping last weekend and it sounds great, super useful, also has a nice band reject out as well.

@Digital Larry, I do highly recommend checking out audulus 3, especially if you have an iPad. Its really rad fun modular synth program, considering you made a modular synth program its right up your alley. I am working with Taylor, the designer of the app on a bunch of things, and if we can get me set up with your code working I might be able to get some sweet graphic enhancement help from him (still haven't gotten it to compile, Ill check your forum again in a moment). His modular app really is the coolest looking and most fluid UI i have seen. really fun to just chill on iPad (I have an iPad pro) and patch my ideas up. :)

here is a video clip of what I am working on bringing to my partially FV-1 based hardware device I am prototyping:
https://www.instagram.com/p/BHaF8hPAKGs ... =axiomcrux
http://MacroMachines.net
Digital Control for your Analog Soul.
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Well I am glad you got it figured out even if my post was not the most helpful thing in the world. Lots of times I am dealing with code that I copied from somewhere else and so there you go.

As you may have guessed, one of the reasons I developed SpinCAD is that Spin ASM gives me a headache even to this day.

If I ever get any spare time I will look into this other thing you are talking about. All FV-1 activities in my own life take place when I am not working on my "real job" which is sufficiently different that I find it difficult to easily switch back and forth - unless someone is paying me.
MacroMachines
Posts: 71
Joined: Fri Dec 12, 2014 10:45 pm
Location: Detroit,MI
Contact:

Post by MacroMachines »

Digital Larry wrote:Well I am glad you got it figured out even if my post was not the most helpful thing in the world. Lots of times I am dealing with code that I copied from somewhere else and so there you go.

As you may have guessed, one of the reasons I developed SpinCAD is that Spin ASM gives me a headache even to this day.

If I ever get any spare time I will look into this other thing you are talking about. All FV-1 activities in my own life take place when I am not working on my "real job" which is sufficiently different that I find it difficult to easily switch back and forth - unless someone is paying me.
hehe "difficult to easily" :P

I am creating audulus modules for each of the opcodes now so that I can test out things like pot mapping and maybe even do simulation. it is also helping a ton in learning in depth how the assembler language works. One of the things about audulus I like and why I mention it, is that its powerful yet casual to work in, IE I never feel like its going to take much time at all to implement and test even complex ideas.
http://MacroMachines.net
Digital Control for your Analog Soul.
Post Reply