Pulling apart the phase shifter program

Algorithm development and general DSP issues

Moderator: frank

Post Reply
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Pulling apart the phase shifter program

Post by Digital Larry »

Let me start by saying that I really love phase shifters and I'd love to be able to get the types of sounds I'm used to from analog phasers out of the FV-1. So I'm deconstructing the supplied phase shifter algorithm and seeing where some variation can be introduced.

First off, I think that 4 all-pass stages are required for each notch you want in the spectrum. A single all pass stage could give you 90 degrees phase shift at the highest frequency, but that is a limit, so mixing 2 stages of that with your dry signal would be more like a low pass filter. So, instead, we use 4 stages and the notch occurs when they are shifting 45 degrees each. Thus for each notch you want, use 4 phase shift stages.

Code: Select all

rdax	p1,1
wrax	temp,1
mulx	phase ; actual phase shift parameter in action
rdax	mono,0.015625	;input to phase shift network
wrax	p1,-1
mulx	phase ; "mixing" parameter, ? is it needed ?
rdax	temp,1
wrax	temp1,0
Second, the structure of the phase shifter provided includes the possibility of internal overflow/distortion, which explains the scaling down by 1/64 of the input signal prior to entering the all pass banks. What I'm not sure of at this point is whether that represents 1/32 for each 4 AP stages, or 1/8th... but I'm guessing it is 1/8th. Then there is the corresponding group of 6 SOF -2.0,0 at the output, whose total gain is the 64 by which we scaled down. So, each bank of 4 APs would need 3 SOF -2.0,0 for gain recovery (and an extra SOF -1.0,0 if you wish not to invert the phase shifted signal). Of course, you can get other sounds by inverting the phase shifted signal, thereby moving the notches. Let's just do it on purpose.

The supplied algorithm multiplies the AP stage output also by the phase parameter, which goes between 0.75 and 0.95 (I'm pretty sure). That is not a huge amount of variation and for my experiments I'm considering just leaving that out completely and doing wet/dry mixing at the very end. Is there any other reason for this?

Next up is the control processing.

Code: Select all

cho rdal,sin1		;read sin1 as +/-1
sof	0.5,0.5		;make positive only sin ranges 0 to 1
log	0.5,0
exp	1,0		;square root function
sof	1,-0.5		;make +/-0.5

sof	1.999,0		;make +/-1 again
mulx	pot2		;pot2 controls width and mix

sof	0.1,0.85
wrax	phase,0		;phase variable ranges 0.8 to 0.95
I'm not going to get into the complications of the S4.19 number representation in between the LOG and EXP instructions.

Based on my understanding of EXP, the parameters given are basically scale and offset after doing 2^(ACC). So is it safe to say that you could replace:

Code: Select all

exp	1,0		;square root function
sof	1,-0.5		;make +/-0.5
with:

Code: Select all

exp	1,-0.5		;square root function
??

The end result of taking the square root of the SIN wave is that you distort the symmetry, which ultimately leads to a subjectively more pleasing sweep on the phase parameter. Conceivably you could take a +/- 1.0 amplitude triangle wave and subject it to the same processing, giving a slightly different sound, or experiment with the center and width endpoints of the resulting LFO signal.

Finally, I found a little article over at CCRMA regarding the all-pass stage, which suggests that there is a structure which uses twice as many delay elements, for the benefit of preventing internal over flow.

https://ccrma.stanford.edu/~jos/pasp/Al ... Combs.html
This can be recognized as direct form I [452], which requires 2M delays instead of M ; however, unlike direct-form II, direct-form I cannot suffer from ``internal'' overflow--overflow can happen only at the output.
The phaser example is one of the more challenging for me to understand. Comments/corrections certainly welcome.
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

The extra MULX PHASE following the all pass stage is required to keep the stage gain at 1.0. I did a little z-plane analysis which I'm sure you'd all find fascinating but I'll let it go for now.

The other thing I would note is that this part of the code is pretty important for setting the sweep range:

Code: Select all

sof   0.1,0.85 
wrax   phase,0
I pulled the LFO off so I could drive the phase parameter directly from a pot and found that most of the action is in the upper half of the range.
Iconnu
Posts: 10
Joined: Thu Apr 17, 2014 7:49 pm

Post by Iconnu »

Larry,

I wanted to post this here because its handy to use when calculating the filter parameters:

first order all-pass filter difference equation:

y(n) = A * x(n) + A * y(n-1) - x(n-1)

Where A =(1 - wp) / (1 + wp)

and wp = pi * (frequency / sampling rate)


As an example, for frequency f1, we can calculate A1 and for another frequency f2 we can calculate A2. We can use a pot or an LFO to sweep from A1 to A2.

A.
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Thanks for the info. I've found part of the challenge with the phase shifter is getting a wide sweep to sound smooth over its range rather than having a big pitch wobble during part of the LFO sweep. I'm not sure what the theoretical criteria for this are, so have been trying different wave shapes and offset/scale. Something with some compression towards the top of the 0 to 1 seems to work best.

Slacker uses 0.25, 0.65 as the SOF parameters in his phaser code and it sounds really nice to me.

Here's another CCRMA article on the DSP phaser:

https://ccrma.stanford.edu/realsimple/D ... lters.html
Iconnu
Posts: 10
Joined: Thu Apr 17, 2014 7:49 pm

Post by Iconnu »

There's a difference between the standard phase shifter effect (N identical stages in series) and what is done in the Univibe (N stages in series, each one tuned differently). I think that's the advantage of having the equation I posted.
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Funny you should mention the Univibe, I was just thinking about it on the way to work this morning. And I didn't realize the stages were different. :shock:

After reading the CCRMA article I became reassured that it could be possible for digital phasers to sound more like the analog ones, but it's the combination of tuning/stages/resonance/LFO that's the secret to any given device's tone. So there's lots of room to experiment, too much room if you ask me! :o

I've made a phaser block in SpinCAD Designer that has adjustable # of stages (2 to 10 by twos) and a single phase input if you don't want to use the LFO. It's simple enough to break out the phase control for each stage to a separate input, so that's coming soon. Looking forward to experimenting with different phase scaling/curves and maybe even two or more LFOs. Although in my experience, the more complex I make things, the worse they sound! :lol: Goal is to find the sweet spot.
amz-fx
Posts: 38
Joined: Wed Sep 06, 2006 7:06 am
Location: Louisiana, USA
Contact:

Re: Pulling apart the phase shifter program

Post by amz-fx »

Digital Larry wrote:First off, I think that 4 all-pass stages are required for each notch you want in the spectrum.
DL,

In analog phasers, two all-pass stages produce a notch, so a 4-stage phaser has two notches. 6-stage phasers have 3 notches, and so on.

regards, Jack
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Thanks Jack. My subsequent tests confirm this to also be the case with the digital phase shifter. Phasers on stun!! weeeooooweeooobeweeepp :D
Iconnu
Posts: 10
Joined: Thu Apr 17, 2014 7:49 pm

Post by Iconnu »

Here's some code for one stage:

;y(n) = A * x(n) + A * y(n-1) - x(n-1)
; can be simplified to
;y(n) = A * (x(n) + y(n-1)) - x(n-1)

; A is a function of the LFO or a POT

ldax xn ; input to stage
rdax ynold,1
mulx A
rdax xold,-1
wrax yn,1 ; output of stage
wrax ynold,0
ldax xn
wrax xold,0
Post Reply