Lowpass with resonance

Algorithm development and general DSP issues

Moderator: frank

livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Lowpass with resonance

Post by livingston »

I've been trying to add a resonance control to the filter from the "reverb flange LP" example program.

Code: Select all

rdax	lp1ar,1
mulx	kfl
rdax	lp1br,1
wrax	lp1br,-1
rdax	lp1ar,kql
rdax	adcr,1
mulx	kfl
rdax	lp1ar,1
wrax	lp1ar,0

rdax	lp2ar,1
mulx	kfl
rdax	lp2br,1
wrax	lp2br,-1
rdax	lp2ar,kql
rdax	lp1br,1
mulx	kfl
rdax	lp2ar,1
wrax	lp2ar,0
I've tried doing feedback in a bunch of different ways but none of them seem to work. What's the standard way of introducing feedback in something like this?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

I believe the 'kql' value is the resonance control in this filter. Try adjusting that value.
Frank Thomson
Experimental Noize
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

In this case I'm looking for a pot-variable resonance. I tried this

rdax lp1ar,1
mulx kfl
rdax lp1br,1
wrax lp1br,-1
rdax lp1ar,kql
mulx pot0
rdax adcr,1
mulx kfl
rdax lp1ar,1
wrax lp1ar,0

rdax lp2ar,1
mulx kfl
rdax lp2br,1
wrax lp2br,-1
rdax lp2ar,kql
mulx pot0
rdax lp1br,1
mulx kfl
rdax lp2ar,1
wrax lp2ar,0

But it doesn't seem to be doing the job right. Is this the wrong approach?
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

I started over, forgetting the above filter structure, trying to build something like a Moog VCF. It doesn't need to be a truly realistic clone, but the basic structure is 4 single-pole filters in series, with negative feedback from the output of the last pole to the input of the first pole. I thought this would be straightforward, but I think there must be something about digital feedback that I'm not getting. I tried this

Code: Select all

;prep pot1 for resonance
rdax	pot1,-1
wrax	res,0

rdax	adcr,1
rdax	lpout,1
wrax	fin,0

rdax   	fin,1.0  		; Read 
rdax  	lp_filt,-1.0 	; ADCL - lp_filt 
mulx   	cutoff 		; * C (POT0 in this case) 
rdax   	lp_filt,1.0 	; +lp_filt 
wrax   	lp_filt,1.0	; write result to lp_filt 

rdax  	lp_filt2,-1.0 	; ADCL - lp_filt 
mulx   	cutoff 		; * C (POT0 in this case) 
rdax   	lp_filt2,1.0 	; +lp_filt 
wrax   	lp_filt2,1.0	; write result to lp_filt 

rdax  	lp_filt3,-1.0 	; ADCL - lp_filt 
mulx   	cutoff 		; * C (POT0 in this case) 
rdax   	lp_filt3,1.0 	; +lp_filt 
wrax   	lp_filt3,1.0	; write result to lp_filt 

rdax  	lp_filt4,-1.0 	; ADCL - lp_filt 
mulx   	cutoff 		; * C (POT0 in this case) 
rdax   	lp_filt4,1.0 	; +lp_filt 
wrax   	lp_filt4,1.0	; write result to lp_filt 

mulx	res
wrax	lpout,1
The filter works by itself but when I add the feedback code it just acts like a volume control. I thought I would just need to multiply the output of the last pole by a negative, then add it to ADCR and put into the first pole input.
curt
Posts: 2
Joined: Sat Jan 02, 2010 8:59 pm

Post by curt »

livingston wrote:The filter works by itself but when I add the feedback code it just acts like a volume control. I thought I would just need to multiply the output of the last pole by a negative, then add it to ADCR and put into the first pole input.
In the analog Moog filter the feedback creates a delay-free loop, whereas the straightforward digital implementation introduces a unit delay. These two papers talk about digital implementations of the ladder filter:

"Analyzing the Moog VCF with Considerations for Digital Implementation", by Stilson and Smith.
"Non-Linear Digital Implementation of the Moog Ladder Filter", by Antti Huovilainen.

I haven't tried it on the FV-1 yet, but it might be challenging. If you don't want to dig through the papers, you could start from one of the examples in the Music-DSP source code archive:
http://musicdsp.org/archive.php?classid=3#24

If your cutoff is going to stay below about 5 kHz you might want to look at the Chamberlin SVF filter, which has much simpler coefficient and per-sample calculation. You can use a cheap approximation for sin(), even linear in some cases. It is a two pole filter, so you would need to cascade two for 24 dB/octave. Here is a simple example:
http://www.musicdsp.org/archive.php?classid=3#142
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Cool, thanks for those suggestions, I've actually looked at those papers and the MusicDSP stuff, but I'm really a noob with programming, so I'm not yet able to decode other programming languages and translate them to the FV-1.

I tried out the State Variable Filter from this thread:

http://www.spinsemi.com/forum/viewtopic.php?t=82

and it works well and sounds good, but when I tried to do another one in series, the program was over the length limit for the FV-1. I think it's more oversampled than necessary, so I could probably do fewer passes and fit it all, but I got a little confused by some of the math. Maybe I should revisit it.
seancostello
Posts: 74
Joined: Mon Sep 11, 2006 10:04 pm

Post by seancostello »

A non-oversampled SVF will work up with cutoffs up to 1/6th the sampling rate. The nice thing about the FV-1 is that it is fixed point, with saturation math, so the filter won't blow up as bad as it would in floating point. It might oscillate, but it won't just "POP!" and go away.

By a nice coincidence, the range from 0 to 1/6th the sampling rate is also the same range as the area where the "proper" coefficient calculation for frequency approximates linear (as Curt pointed out above). So no sine() needed for the usable range. Not sure if this can be extended to the oversampled version. Anyway, this makes envelope filters with a SVF a piece of cake.

Sean Costello
http://www.valhalladsp.com
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Yep, turns out the SVF works well for my purposes. Cut the oversampling to just one extra pass, then doubled it. Getting lots of distortion with high resonance, but I think I can work it out. Thanks guys.
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

So I used the SVF and cut it to only double sampling. I'm getting lots of distortion like this and I assume it has to do with that scaling coefficient - I'm not really sure what it does and how it should be modified when sampling fewer times. Any suggestions? It's this code:

http://www.spinsemi.com/forum/viewtopic.php?t=82
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Having more time to think about this, I'm wondering if I could do the feedback in hardware, i.e., use 4 single pole filters in series, then output the audio and send some of it back into the input pin. This would seemingly get rid of the feedback delay, right?
seancostello
Posts: 74
Joined: Mon Sep 11, 2006 10:04 pm

Post by seancostello »

livingston wrote:Having more time to think about this, I'm wondering if I could do the feedback in hardware, i.e., use 4 single pole filters in series, then output the audio and send some of it back into the input pin. This would seemingly get rid of the feedback delay, right?
If you are talking about generating the filters on the FV-1, it will actually generate a much larger delay. You will still have the single sample delay, as the algorithm can't process a new input until it generates a new output. The feedback outside the chip will also create a delay of a few milliseconds, due to the design of the A/D and D/A converters. Pretty much any A/D and D/A converters will have some amount of delay present.

Sean Costello
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Hmm, I didn't realize it would be so difficult to do a 4-pole filter with variable Q.

The SVF doesn't work because I think I do actually need all that oversampling, and there isn't enough program space to do a second pass of the oversampled filter.

The one in my first post doesn't work because it doesn't have variable Q.

The straightforward Moog workalike won't work because of the feedback delay.

What other options are there? If someone could just give me a nudge in the right direction, I would be grateful. Maybe I need to learn C++ and dig into those examples, but the point of the FV-1 for me was to avoid that... :?

Edit: Hey Sean, seems you were asking this same question elsewhere online over 10 years ago. Maybe I should try that limiting technique you mention with 2 SVFs to fix my problem with distortion with 2 of these in series.
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

I think everyone's silence was a sort of Karate Kid-style method of teaching: "you will learn by figuring it out for yourself - if we help you you'll never get good at problem solving." I'm going to choose to look at it that way, anyway. :)

So I pondered it and stared at various versions of code forever and finally figured it out.

Code: Select all

rdax lp1ar,1 
mulx kfl 
rdax lp1br,1 
wrax lp1br,-1 
rdax lp1ar,kql 
mulx pot0 
rdax adcr,1 
mulx kfl 
rdax lp1ar,1 
wrax lp1ar,0 

rdax lp2ar,1 
mulx kfl 
rdax lp2br,1 
wrax lp2br,-1 
rdax lp2ar,kql 
mulx pot0 
rdax lp1br,1 
mulx kfl 
rdax lp2ar,1 
wrax lp2ar,0 
This doesn't work because the pot is multiplying everything in the accumulator, not just LP1AR. So I just had to save off the ACC to a temp register, read LP1AR, mulx pot0, then add in the temp register.

So simple!
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

In all honesty, my silence was "I'm at the dentist/NAMM/fell asleep before answering/Sean is responding and he knows more about filters than I" based. The last week has been busy!!
Frank Thomson
Experimental Noize
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

Well, I was just kidding. I don't feel I'm entitled to step-by-step hand-holding here... The development board would have to be a lot more expensive to cover that!

I do hope that this forum will grow to a point like DIYstompboxes eventually, which is one reason I encourage people to start working with the FV-1 if they want to do more complex things with effects. I prefer the easy path to that of the trailblazer :wink: , but I guess by the time this forum gets big I will be one of the grizzled elders who knows what he's doing.

In all seriousness, though, it's good that I'm slowly getting deeper into the code, so I don't have to freak out when my cut-and-paste method hits a wall. That thing about giving a man a fish...
Post Reply