## reconstruct phase-shifted sine tone

Started by 7 years ago●5 replies●latest reply 7 years ago●183 viewsHi,

I am trying an example matlab code for reconstructing a sine-tone using window OLA, using a Hanning window (periodic). Sampling frequency is 8kHz and the tone frequency is 20 hz (just for a trial). It is working as expected and I can get the sine-tone out using OLA. Now, I would like to get the phase-shifted sine tone (say by pi/2) using OLA. For this, I am multiplying the windowed frame by exp(-j pi/2) before OLA operation. I am somehow loosing the phase continuity and my output is all over the place. Any thoughts ? I believe, I am missing something fundamental here..

note: fft and frame size are 128, shift is 64.

regards

asm

Just to make sure I understand the question ...

You are taking a real sinusoid sin( 2 pi 20/8000 n) and multiplying by a complex phase shifter e^-i pi/2. How are you returning to a real signal? If you are just doing Re() then what you are doing is cos(pi/2)sin(wn) = 1/2(sin(wn+pi/2) + sin(wn-pi/2)).

Is that what you are doing ?

Y(J)S

You have a few things wrong:

1) As Y(J)S alluded to, real valued signals have the top half of the DFT as the conjugate mirror of the bottom half so if you rotate them all the same, except for very special cases, you will no longer have conjugate pairs in the bins and therefore the inverse will not be a real signal. You can overcome this by just rotating the bottom half and then constructing the top half by using the conjugates of the bottom half.

2) The amount you rotate a bin value represents a phase shift in relation to the wavelength of that bin, not the frame of your sample space. So the same rotation on all the bins represents different length phase shifts in the time domain.

This technique is only going to work seamlessly for a strictly periodic signal. One frame does not have any idea what the next frame holds. It may be helpful for you to state what the ultimate goal that you are trying to achieve is.

Ced

Edit: I still don't think it will work because of the "wrap around" nature of the DFT.

Hi,

Thanks for your reply.

All I am trying is to check if a phase-shift (of any radians) of sine wave is possible using window OLA method.

Here are my steps:

1. Frame the signal using Hanning window (periodic in order to satisfy COLA condition).

2. take FFT of the windowed frame.

3. Preserve top half of fft (includes DC and Pi frequency).

4.Optional: Do spectral modifications.

5. Flip and conjugate the top half (excluding DC and Pi) and append to the spectrum.

6. Take IFFT.

7. Do Overlap-add to generate real output.

Now, this all is working on its own (without step 4).

If I try to introduce a phase shift in step 4, by multiplying FFT by a phase shifter, e.g.exp(-j pi/2), then I get distortion in the output signal.

I believe the reason for this is my one frame of sine wave does not contain the complete cycles.

regards

asm

Yep, this is your main problem. This is why I added my edit of "the 'wrap around' nature of the DFT." Your technique is only going to work for tones with integer frequencies relative to your sampling frame.

You have accounted for my point #1, but you still haven't dealt with point #2. Taking your frame size of 128, let's look at bin index 4 which represents a tone with 32 samples per cycle. If you shift that a quarter cycle you are shifting it by 8 sample points. Compare that to bin index 2. The tone has 64 samples per cycle and a quarter cycle is a shift of 16 points. Thus when you decompose your signal into the constituent tones of the DFT, you are shifting the constituents different values and your reconstruction is not going to retain it's original form.

The extension of an inverse DFT past the frame size creates a repeat pattern of the sampled frame. So if you shift it properly, the boundary between repeat frames will be shifted into your frame. Unless you have an integer frequency tone, this boundary is going to be discontinuous either in the value or the derivative, or both. The windowing and adding will mitigate this, but not eliminate it.

Hope this helps,

Ced

Thanks Ced for the wonderful explanation. I appreciate it. My final aim is to assess if I can apply a phase-shift to some frequencies in speech/audio signal and if it causes audible distortion.

regards

asm.