DSPRelated.com
Forums

Implementing a Phase Shift in Matlab

Started by owen...@auburn.edu October 27, 2006
I have a signal measured from a mechanical system. What I want to do is shift the signal in phase, but leave the magnitudes the same. I guess this would basically just be an allpass filter (???). The amount of phase shift is dependant on frequency, but not linearly. Each frequency component is shifted by a different amount. What is the most appropriate way of doing this? I've tried searching around on the board, but haven't had much luck. Could somebody help me get going in the right direction?

Thanks a bunch,
Taylor
Hello:

If I recall correctly, a phase shift is equivalent to multiplication by a complex exponential. That is, if f(t) is your signal then your new signal will be

g(t)=f(t)*e^( j*p(w)t ) where j=sqrt(-1), e=2.7169... and p(w) is your frequency function

this will have the effect of

G(w)=F( w - p(w) ).

so your frequencies are shifted retaining the magnitude.

o...@auburn.edu wrote:
I have a signal measured from a mechanical system. What I want to do is shift the signal in phase, but leave the magnitudes the same. I guess this would basically just be an allpass filter (???). The amount of phase shift is dependant on frequency, but not linearly. Each frequency component is shifted by a different amount. What is the most appropriate way of doing this? I've tried searching around on the board, but haven't had much luck. Could somebody help me get going in the right direction?

Thanks a bunch,
Taylor
Hello Taylor

> I have a signal measured from a mechanical system. What I want to do is shift the signal in phase, but leave the magnitudes the same. I >guess this would basically just be an allpass filter (???).

Yes

> The amount of phase shift is dependant on frequency, but not linearly.
> Each frequency component is shifted by a different amount. What is the most appropriate way of doing this?
> I've tried searching around on the board, but haven't had much luck.
> Could somebody help me get going in the right direction?
>

It is simple to do that in the frequency domain.
Take an fft of the whole signal and multiply each component (as a complex number)
by the complex number cos(p) + i * sin(p)
where p is the phase-shift given in radians
Afterwards take the inverse transform and you are done.

gr.
Anton
Hello Taylor,

>I have a signal measured from a mechanical system. What I want to do is >shift the signal in phase, but leave the magnitudes the same. I guess this >would basically just be an allpass filter (???). The amount of phase shift >is dependant on frequency, but not linearly. Each frequency component is >shifted by a different amount. What is the most appropriate way of doing >this? I've tried searching around on the board, but haven't had much luck. >Could somebody help me get going in the right direction?

You can do it easily in the frequency domain.
Take the fft oh the whole signal and multiply
each component with
exp(i*p)
where p is the desired phase-shift in radians.
And you need to take care that you do not destroy
the mirror-symmetry of the spectrum (for a real-numbered signal)
so if you multiply component n with p
than multiply component (N - n) with the same number p.

gr.
Anton
Thanks a bunch. I got it working by using this method. I had been trying to do it by computing the phase and magnitude of the original signal, then shifting the phase by just adding an amount to the phase angles, then reconstructing all the terms. However, that was kinda cumbersome to implement after having to figure out all the signs of the terms, etc. Simply multiplying by cos(p) + i * sin(p) is much easier to implement.

Thanks a lot to everyone for their input.

Taylor

Hello Taylor
>
>> I have a signal measured from a mechanical system. What I want to do is shift the signal in phase, but leave the magnitudes the same. I > guess this would basically just be an allpass filter (???).
>
>Yes
>
>> The amount of phase shift is dependant on frequency, but not linearly.
>> Each frequency component is shifted by a different amount. What is the most appropriate way of doing this?
>> I've tried searching around on the board, but haven't had much luck.
>> Could somebody help me get going in the right direction?
>>
>
>It is simple to do that in the frequency domain.
>Take an fft of the whole signal and multiply each component (as a complex number)
>by the complex number cos(p) + i * sin(p)
>where p is the phase-shift given in radians
>Afterwards take the inverse transform and you are done.
>
>gr.
>Anton
Taylor Owensat-

> Thanks a bunch. I got it working by using this method. I had been trying
> to do it by computing the phase and magnitude of the original signal, then
> shifting the phase by just adding an amount to the phase angles, then
> reconstructing all the terms. However, that was kinda cumbersome to
> implement after having to figure out all the signs of the terms, etc.
> Simply multiplying by cos(p) + i * sin(p) is much easier to implement.

Good that you've made progress. Please keep in mind that it's a simpler thing when
you can FFT the whole signal. In a real-time, continuous system you would have to
partition the input into frames (size based on application and nature of the data).
While the same concepts of what you're doing now would apply, you would have to be
careful of phase discontinuity when reconstructing frames of the time domain signal.

-Jeff
> Hello Taylor
> >
> >> I have a signal measured from a mechanical system. What I want to do is shift the signal in phase, but leave the magnitudes the same. I > guess this would basically just be an allpass filter (???).
> >
> >Yes
> >
> >> The amount of phase shift is dependant on frequency, but not linearly.
> >> Each frequency component is shifted by a different amount. What is the most appropriate way of doing this?
> >> I've tried searching around on the board, but haven't had much luck.
> >> Could somebody help me get going in the right direction?
> >>
> >
> >It is simple to do that in the frequency domain.
> >Take an fft of the whole signal and multiply each component (as a complex number)
> >by the complex number cos(p) + i * sin(p)
> >where p is the phase-shift given in radians
> >Afterwards take the inverse transform and you are done.
> >
> >gr.
> >Anton