phase shifting in degrees

cebec's icon

What's the simplest way to phase shift a signal, for example, one entering via adc~, in degrees, from 0 to 360? All of the methods/externals I've found so far are not as straightforward as I expected. Am I missing something obvious with a combination of native MSP objects?
Thanks!
Matt

skrasms's icon

Do you mean a constant phase shift that is the same phase difference at every frequency? When I want to do that I make a pfft~ object for it:

Max Patch
Copy patch and select New From Clipboard in Max.

cebec's icon

Thanks! This is great!

Valiumdupeuple's icon

Your solution works perfectly Skrasms, thx.
I'd still love to know how to achieve the same thing without the expense of pfft~, though. Can someone help ?
Cheers
C.

hz37's icon
Max Patch
Copy patch and select New From Clipboard in Max.

For a single frequency signal you can use a [delay~] object and pass it the amount of samples you need to delay the signal in order to achieve the desired phase shift.

Valiumdupeuple's icon

Thanks HZ37 but, as the OP, I'm asking about phase shifting of the whole frequency spectrum, or as Skrasms said "same phase difference at every frequency".
Cheers.

Valiumdupeuple's icon

For the record, I've replaced fft~ by hilbert~ and it works well for what I want.

Peter McCulloch's icon

You can also use allpass filters to do more targeted phase shifts. (Cascade~ + filtergraph~).

IIRC, the version of the Hilbert transform in the IRCAM jimmies library used an allpass filter (or filters).

Roman Thilenius's icon

whats wrong with [phaseshift~] ?

Valiumdupeuple's icon

I don't know Roman, I just couldn't achieve what I was after with [phaseshift~]. Maybe I've missed something.
But I succeed by using Skrasms' code and replacing its [fft] objects by [hilbert~].
btw, thanks everyone for your suggestions.

Roman Thilenius's icon

@peter: jimmies used biquads. thats where i have stolen mine from. :) for 0 and 90 degrees it works great.

Shauk Khan's icon

I have a 5.1 setup with three front speakers and two rear speakers, i am looking for a way to decorrelate the rear speakers from the front. So far from my reading and going through the blogs what i understood is i can use allpass filters to do the task as they keep the magnitude same and introduces random phases to signal. Now i have a cascade of 8 all pass filters, each of them is a single biquad, implemented from max msp, at different frequencies and hoping for a decorrelated signal. Does any one have an idea how many allpass filters are needed and at which frequency steps they should be placed

what i know is to have a fully decorrelated signal i need to have a correlation coefficient of zero between two signal, any idea how can i measure the correlation from max msp.

Peter McCulloch's icon

My guess, and this is purely speculative, would be that you should concentrate on the frequencies that are most perceptually prominent. A chart of Equal Loudness Curves (sometimes called Phon Curves) would be a good guide. The 3-5kHz region is pretty sensitive in our hearing, so I'd start there.

The other resource that might be useful is to check out the allpass sections of reverberators to see what multiplication values they're using for the allpasses. If they're different values, that's potentially useful information.

Jonathan Hart's icon

I'm looking to do the same thing - shift all frequencies by the same amount - but the pfft~ patch above doesn't work the way I expected. When mixing the output with the original signal, I can definitely hear a difference, but it doesn't cancel out completely at 180. What am I missing?

Robert Koster's icon

Hey peeps, just wanted to chime in because i've played around with this a bit (over the space of a couple years on and off) and hilbert~ does the job but it offsets the phase by an unmeasurable and arbitrary amount before you even give it any amount of phase offset, therefore making it impossible to actually shift audio by a measurable amount, at least in my experience. Perhaps there is something I'm missing?

Roman Thilenius's icon


a hilbert transform doesnt rotate phase.

Alois Cerbu's icon

I believe a Hilbert transform rotates all phases by pi/2.

Roman Thilenius's icon

... or 90º

Peter McCulloch's icon

Hilbert~ will produce two signals which are (for most audible frequencies) 90 degrees apart relative to each other, but this relationship is not true relative to the input. The reason for this is that Hilbert~ is using cascades of allpass filters to create this relationship, and allpass filters aren’t linear phase.

It is possible to do the Hilbert transform with a linear phase FIR filter, but that will introduce latency equal to the midpoint of the filter‘s length. It’d also probably require a fairly long filter to ensure that it can cover the necessary range of frequencies.

Alois Cerbu's icon

@Peter, thanks - very helpful!

Robert Koster's icon

Yeah cheers for clarification Peter. There is no way to find the phase difference between the output and input of hilbert~ is there? I assume that the best option for doing something like this would be using fft~?

Peter McCulloch's icon

There’s nothing straightforward that comes to mind. If you know the algorithm used for the allpass cascade, you could calculate it for various frequencies (because the amount of phase offset will be different across the entire spectrum)

What I’ve usually done is to let the left outlet become the dry signal (subsequently ignoring the actual dry signal) and then treat the right outlet as the wet signal.

Roman Thilenius's icon


for most applications you wouldnt need to know anything about the difference between input and output(s) because the real output is sonically very close to the input.

i believe there is no easy solution without using fft phase bins.