Shift Phase of Specific fft bin

Joel L's icon

I asked a similar question, but I think I was too specific, so here's a more general question:

How do I shift the phase of a specific fft bin?

Currently, I'm using pfft~ > cartopol~ > +~ > phasewrap~ > poltocar > fftout~. However, this shifts the entire signal rather than a specific fft bin.

Any ideas?

Roman Thilenius's icon

you could filter out only all phase bins #17 and process only those, but it will be a bit difficult to do anything meaningful with a single bin.

it can be used to do a more finetuned onset detection and things like that, but i have no idea about the math required.

Joel L's icon

Thanks for your reply, Roman.

I should have been more clear in my question. I am trying to make a Phase EQ, so I need to adjust phase of each fft bin by (potentially) different amounts. For example, I might want to shift phase in bins 0-10 by 90 degrees, then bins 11-20 by 180 degrees, then 21-30 by 45 degrees, etc.

I know its possible to do exactly that for Magnitude using pfft~, but I can't figure out how to do so for Phase...

What would be the best way to achieve this?

Roman Thilenius's icon

well the principle is always the same, no? the index output in pfft gives you the "counter" and then you can do selective operations.

Joel L's icon

Yup, I've tried that. The strange thing is that if I apply a different factor to the Magnitude and Phase, the output becomes unstable (tried with a cycle~ 1000 input).

👽'tW∆s ∆lienz👽's icon

pfft~ > cartopol~ > +~ > phasewrap~ > poltocar > fftout~

what MZED advised in the other thread is correct, you can use ==~ to detect by bin as Roman is also advising here...
applying +~ only to the data coming out of the right-outlet of cartopol~(you don't want to "apply a different factor" to the magnitude if you're creating a 'phase eq')...
the factor you add using +~ can be controlled with gate~ and gate~ can be opened or closed using the ==~ detecting specific bins(but there are so many ways of interfacing this so that you can get specific control over every single bin, i can't really begin to explain that part for you without seeing your patch.. and even then, i might not be able to 😅 you could even try mc.pfft~ and each bin controlled by mc-based connections from outside, keep in mind with mc.pfft~, the output is summed same as in mc.poly~ so you can't split off by voice/bin at the output...)...
(yet another tangent: another way to perform transformation per-bin could be sah~ instead of gate~, but you can see the difference that happens at their output when they are triggered to let values through as opposed to when they're not and decide why one might be better than the other in different contexts - it depends on how you set up your patch... )
then, you pass that phase part only into phasewrap~, you pass the magnitude coming out of cartopol~ straight into the left-inlet of poltocar~(maybe this is what you're doing but your wording here doesn't indicate that: "its possible to do exactly that for Magnitude using pfft~"... magnitude is not calculated in the same terms as phase(i've had trouble with this myself, but i think magnitude can go pretty high, easily causing the signal to be too loud and distorted)... phase is from -π to π(phasewrap~ ensures this no matter what you add to the phase before that)... so to start off, i'd advise not working any transformation over the magnitude at all until you understand everything fully about the phase part), the output(after transformation) from phasewrap~ then goes into the right inlet of poltocar~... finally, with poltocar~ returning the signal from magnitude/phase terms back to real/imaginary terms, you send those into fftout~

if you still have trouble with this, i'd advise posting your patch back in the other thread, you mentioned you have one already there, and here and there you've mentioned you've tried certain things so i must assume you have one(since MZED helped you first with good ideas(also a genius in his own right at this stuff)... he might get the notification and be interested in seeing it, either way, it'll be easier to show in a patch already created rather than create something from scratch especially where anything FFT-wise is concerned).
FFT is something much more complex than other realms of DSP, and also takes much time to learn on its own outside of Max, so hopefully this helps explain why it's difficult to get patch-specific help without starting from your specific patch(even after seeing the patch, it might still be difficult... these things can get too time-consuming for others to explain... i myself learned what little i know of this by reading 'Musimathics' (specifically: Vol 2) by Gareth Loy and a few other texts... it was not easy and i still struggle)...
hope this helps 🍻