# A Stupid FM Demod Question?

Started by April 3, 2007
```Hi Folks,

If you want to extract the frequency from a complex signal that
contains a single, time-varying frequency component, then the
straightforward method would be to determine the phase of the
input signal and then run that phase into a differentiator. I'm
thinking of a full-blown FIR differentiator with, say, 32 or
more taps.

The problem is, the phase has those bothersome discontinuities
around +/- pi. You could unwrap it, but in fixed-point, you
can only unwrap so far (think of what a single high-frequency
sinusoid would result in phase-wise) before wrapping around
the two's complement number.

So, how to do? How do you get a phase input that's unwrapped
for each M-1 previous samples into the FIR differentiator?

This seems like a simple and common problem, but I'm coming
up with zero. Maybe it's an off-night for me.
--
%  Randy Yates                  % "Bird, on the wing,
%% Fuquay-Varina, NC            %   goes floating by
%%% 919-577-9882                %   but there's a teardrop in his eye..."
%%%% <yates@ieee.org>           % 'One Summer Dream', *Face The Music*, ELO
```
```Randy Yates wrote:
> Hi Folks,
>
> If you want to extract the frequency from a complex signal that
> contains a single, time-varying frequency component, then the
> straightforward method would be to determine the phase of the
> input signal and then run that phase into a differentiator. I'm
> thinking of a full-blown FIR differentiator with, say, 32 or
> more taps.
>
> The problem is, the phase has those bothersome discontinuities
> around +/- pi. You could unwrap it, but in fixed-point, you
> can only unwrap so far (think of what a single high-frequency
> sinusoid would result in phase-wise) before wrapping around
> the two's complement number.
>
> So, how to do? How do you get a phase input that's unwrapped
> for each M-1 previous samples into the FIR differentiator?
>
> This seems like a simple and common problem, but I'm coming
> up with zero. Maybe it's an off-night for me.

Randy,

If you calculate the change in phase at each sample interval, then you
don't need the differentiator.  You already have frequency.

I don't think the discontinuities will then be a problem. Provided the
modulator produces phase changes of less than pi in any sample interval
then there should be no ambiguity problem in determining the phase change.

Regards,
John
```
```John Monro <johnmonro@optusnet.com.au> writes:

> Randy Yates wrote:
>> Hi Folks,
>> If you want to extract the frequency from a complex signal that
>> contains a single, time-varying frequency component, then the
>> straightforward method would be to determine the phase of the
>> input signal and then run that phase into a differentiator. I'm
>> thinking of a full-blown FIR differentiator with, say, 32 or
>> more taps.
>> The problem is, the phase has those bothersome discontinuities
>> around +/- pi. You could unwrap it, but in fixed-point, you
>> can only unwrap so far (think of what a single high-frequency
>> sinusoid would result in phase-wise) before wrapping around
>> the two's complement number.
>> So, how to do? How do you get a phase input that's unwrapped
>> for each M-1 previous samples into the FIR differentiator?
>> This seems like a simple and common problem, but I'm coming
>> up with zero. Maybe it's an off-night for me.
>
> Randy,
>
> If you calculate the change in phase at each sample interval, then you
> don't need the differentiator.  You already have frequency.
>
> I don't think the discontinuities will then be a problem. Provided the
> modulator produces phase changes of less than pi in any sample
> interval then there should be no ambiguity problem in determining the
> phase change.

Hi John,

Well that's what I *was* doing, but I started questioning the accuracy
of the "two-sample differentiator." How do you know if the "two-sample
differentiator" is good enough? What kind of distortion am I introducing
when I use that as opposed to a more accurate multi-tap differentiator?
--
%  Randy Yates                  % "Midnight, on the water...
%% Fuquay-Varina, NC            %  I saw...  the ocean's daughter."
%%% 919-577-9882                % 'Can't Get It Out Of My Head'
%%%% <yates@ieee.org>           % *El Dorado*, Electric Light Orchestra
```
```Randy Yates <yates@ieee.org> writes:

> John Monro <johnmonro@optusnet.com.au> writes:
>
>> Randy Yates wrote:
>>> Hi Folks,
>>> If you want to extract the frequency from a complex signal that
>>> contains a single, time-varying frequency component, then the
>>> straightforward method would be to determine the phase of the
>>> input signal and then run that phase into a differentiator. I'm
>>> thinking of a full-blown FIR differentiator with, say, 32 or
>>> more taps.
>>> The problem is, the phase has those bothersome discontinuities
>>> around +/- pi. You could unwrap it, but in fixed-point, you
>>> can only unwrap so far (think of what a single high-frequency
>>> sinusoid would result in phase-wise) before wrapping around
>>> the two's complement number.
>>> So, how to do? How do you get a phase input that's unwrapped
>>> for each M-1 previous samples into the FIR differentiator?
>>> This seems like a simple and common problem, but I'm coming
>>> up with zero. Maybe it's an off-night for me.
>>
>> Randy,
>>
>> If you calculate the change in phase at each sample interval, then you
>> don't need the differentiator.  You already have frequency.
>>
>> I don't think the discontinuities will then be a problem. Provided the
>> modulator produces phase changes of less than pi in any sample
>> interval then there should be no ambiguity problem in determining the
>> phase change.
>
> Hi John,
>
> Well that's what I *was* doing, but I started questioning the accuracy
> of the "two-sample differentiator." How do you know if the "two-sample
> differentiator" is good enough? What kind of distortion am I introducing
> when I use that as opposed to a more accurate multi-tap differentiator?

Another questtion: Suppose we DO need to use a multitap filter for good
accuracy. If we are using say 16-bit fixed-point two's complement
arithmetic, and we scale the arctan output so that -pi corresponds
precisely to -32768 and +pi to +32768, then would the differentiator
MAC (assume we're using a 32-bit accumulator for the products) always
wrap back to the proper interval? Kinda' like the fixed-point integrators
do on a CIC? Would this happen? How to show?
--
%  Randy Yates                  % "Rollin' and riding and slippin' and
%% Fuquay-Varina, NC            %  sliding, it's magic."
%%% 919-577-9882                %
%%%% <yates@ieee.org>           % 'Living' Thing', *A New World Record*, ELO
```
```
Randy Yates wrote:

> Hi Folks,
>
> If you want to extract the frequency from a complex signal that
> contains a single, time-varying frequency component, then the
> straightforward method would be to determine the phase of the
> input signal and then run that phase into a differentiator.

The straightforward way would be not to use the phase representation.
Work with the complex derivatives directly:

IdQ/dt - QdI/dt
---------------
I^2  + Q^2

I'm
> thinking of a full-blown FIR differentiator with, say, 32 or
> more taps.
>
> The problem is, the phase has those bothersome discontinuities
> around +/- pi.

Yes, the phase has to be unwrapped, unless the differentiator is trivial
twos complement [1 -1] or like.

DSP and Mixed Signal Design Consultant

http://www.abvolt.com

```
```Randy Yates wrote:
> John Monro <johnmonro@optusnet.com.au> writes:
>
>> Randy Yates wrote:
>>> Hi Folks,
>>> If you want to extract the frequency from a complex signal that
>>> contains a single, time-varying frequency component, then the
>>> straightforward method would be to determine the phase of the
>>> input signal and then run that phase into a differentiator. I'm
>>> thinking of a full-blown FIR differentiator with, say, 32 or
>>> more taps.
>>> The problem is, the phase has those bothersome discontinuities
>>> around +/- pi. You could unwrap it, but in fixed-point, you
>>> can only unwrap so far (think of what a single high-frequency
>>> sinusoid would result in phase-wise) before wrapping around
>>> the two's complement number.
>>> So, how to do? How do you get a phase input that's unwrapped
>>> for each M-1 previous samples into the FIR differentiator?
>>> This seems like a simple and common problem, but I'm coming
>>> up with zero. Maybe it's an off-night for me.
>> Randy,
>>
>> If you calculate the change in phase at each sample interval, then you
>> don't need the differentiator.  You already have frequency.
>>
>> I don't think the discontinuities will then be a problem. Provided the
>> modulator produces phase changes of less than pi in any sample
>> interval then there should be no ambiguity problem in determining the
>> phase change.
>
> Hi John,
>
> Well that's what I *was* doing, but I started questioning the accuracy
> of the "two-sample differentiator." How do you know if the "two-sample
> differentiator" is good enough? What kind of distortion am I introducing
> when I use that as opposed to a more accurate multi-tap differentiator?

Hi Randy,
I think using your original method, all you are introducing is errors in
the frequency domain samples due to the amplitude-quantisation and the
timing-jitter that is inherent in the original time-domain sampling
process.

Depending on the final baseband bandwidth you need, you may be able to
clean up the frequency-domain signal using a LP filter, in effect
averaging the frequency-domain samples you have generated.  It seems to
me that the  signal will then have will be the best possible signal that
can be extracted given the characteristics of the time-domain samples.

Regards,
John
```
```Vladimir Vassilevsky <antispam_bogus@hotmail.com> writes:

> Randy Yates wrote:
>
>> Hi Folks,
>> If you want to extract the frequency from a complex signal that
>> contains a single, time-varying frequency component, then the
>> straightforward method would be to determine the phase of the
>> input signal and then run that phase into a differentiator.
>
> The straightforward way would be not to use the phase
> representation. Work with the complex derivatives directly:
>
> IdQ/dt - QdI/dt
> ---------------
> I^2  + Q^2

I guess the key advantage is that you don't have to implement an
arctan function?

Would you use an FIR differentiator to get Q' and I', making sure
they're properly time-aligned with the I and Q values?
--
%  Randy Yates                  % "She has an IQ of 1001, she has a jumpsuit
%% Fuquay-Varina, NC            %            on, and she's also a telephone."
%%% 919-577-9882                %
%%%% <yates@ieee.org>           %        'Yours Truly, 2095', *Time*, ELO
```
```Randy Yates wrote:
> > Randy Yates wrote:
> >
> >> If you want to extract the frequency from a complex signal that
> >> contains a single, time-varying frequency component, then the
> >> straightforward method would be to determine the phase of the
> >> input signal and then run that phase into a differentiator.
> >
> > The straightforward way would be not to use the phase
> > representation. Work with the complex derivatives directly:
> >
> > IdQ/dt - QdI/dt
> > ---------------
> > I^2  + Q^2
>
> I guess the key advantage is that you don't have to implement an
> arctan function?
>
> Would you use an FIR differentiator to get Q' and I', making sure
> they're properly time-aligned with the I and Q values?

actually Randy, you *do* have to implement an arctan() function for
small angles, but you *don't* have to compute a derivative explicitly
from these discrete samples (using some big FIR).

omega[n] = arg{ I[n] + j*Q[n] }  -  arg{ I[n-1] + j*Q[n-1] }

= arctan( Q[n]/I[n] ) - arctan( Q[n-1]/I[n-1] )

= arctan( (Q[n]*I[n-1] - I[n]*Q[n-1]) / (I[n]*I[n-1]
+Q[n]*Q[n-1]) )

the measure omega[n] is simple that of how much the phase of I + j*Q
has advanced from the phase of the previous sample.  isn't that what
frequency is?  how much (in a given period of time) the phase angle

r b-j

```
```"robert bristow-johnson" <rbj@audioimagination.com> writes:

> Randy Yates wrote:
>> > Randy Yates wrote:
>> >
>> >> If you want to extract the frequency from a complex signal that
>> >> contains a single, time-varying frequency component, then the
>> >> straightforward method would be to determine the phase of the
>> >> input signal and then run that phase into a differentiator.
>> >
>> > The straightforward way would be not to use the phase
>> > representation. Work with the complex derivatives directly:
>> >
>> > IdQ/dt - QdI/dt
>> > ---------------
>> > I^2  + Q^2
>>
>> I guess the key advantage is that you don't have to implement an
>> arctan function?
>>
>> Would you use an FIR differentiator to get Q' and I', making sure
>> they're properly time-aligned with the I and Q values?
>
> actually Randy, you *do* have to implement an arctan() function for
> small angles, but you *don't* have to compute a derivative explicitly
> from these discrete samples (using some big FIR).
>
> omega[n] = arg{ I[n] + j*Q[n] }  -  arg{ I[n-1] + j*Q[n-1] }
>
>      = arctan( Q[n]/I[n] ) - arctan( Q[n-1]/I[n-1] )
>
>      = arctan( (Q[n]*I[n-1] - I[n]*Q[n-1]) / (I[n]*I[n-1]
> +Q[n]*Q[n-1]) )

How did you get from the second line to the third?

> the measure omega[n] is simple that of how much the phase of I + j*Q
> has advanced from the phase of the previous sample.  isn't that what
> frequency is?  how much (in a given period of time) the phase angle

I always thought that frequency is the derivative of phase, f = dtheta/dt.
That's the gist of my question. Do I need to perform a full derivative
or is theta2 - theta1 perfect or good enough?

Seems like, going back to first semester calculus, theta2-theta1
is the average slope in the period t1 to t2, and that the true
instantaneous slope would be dtheta/dt.
--
%  Randy Yates                  % "Remember the good old 1980's, when
%% Fuquay-Varina, NC            %  things were so uncomplicated?"
%%% 919-577-9882                % 'Ticket To The Moon'
%%%% <yates@ieee.org>           % *Time*, Electric Light Orchestra
```
```If you scale the phase to the full width of your data word, i.e. Pi = 32767
for 16-bit, then the subtraction is automatically modulo Pi and there is no
issue. For example,

x(0) = -.9Pi
x(1)  = .9Pi

then x(1)-x(0) = 1.8Pi which is -.2Pi because of the overflow.

-Clark

```