# Fourier series of sign(cos(.)) in simulation and practical mixer simulation

Started by July 15, 2014
```Hi,

I simulate (or want to simulate) an RF system. My simulation Nyquist
rate is 50GHz, the signals are 8 Msamples long and there is a 5MHz
transmission at 1GHz (using standard I/Q modulation).

In any case, I am playing around with modulation.

When I create a modulation sequence

fc = 1GHz + 6.103515624999999kHz   % note the non-integer multiple
m1(t) = cos(2*pi*fc*t)

then I get a strong single peak at fc (down to -250dBFS, i.e. numerical
precision). There is no leakage visible!

In a practical system however, I cannot multiply by a real sinusoid. For
example, a popular mixer is the passive mixer which just turns on and
off switches. The modulation sequence should then correspond to (first
order)

m2(t) = sign(m1(t)) = sign(cos(2*pi*fc*t))

What I would expect now are peaks at k*fc (k odd integer). They
correspond to the Fourier coeffcients, spaced fc apart because the
sequence is still periodic with 1/fc.

I see these peaks in the spectrum. What I do see also, however, are
peaks which are spaced 305.1758kHz apart. And they are pretty high (up
to -30dBFS). And their shape reminds me on leakage.

But why would I see lots of leakage with sign(cos(.)) but not cos(.)?
What's also against leakage is that windowing the signal (with any
window) does not change anything.

My only plausible explanation is that the hard non-linearity due to the
sign operation causes an infinite amount of Fourier coefficients (i.e.,
infinite bandwidth) and I do only have 25GHz so what I see is aliasing.

However:

- Can anyone confirm that it's aliasing?

- Why is the spacing 305.1758kHz? This sounds so arbitrary! And if I
change fc, e.g.

fc=1GHz+7.669903939428206MHz

the distance between the spurs is increased to 488.281kHz and spurs
are much lower (-80dBFS)
I cannot relate these numbers to anything.

- If this is the case, how would you actually simulate a real passive
mixer? Would you really need to increase the simulation fs until now
aliasing occurs any more?

Clearly, in a physical system the Fourier coefficients will become zero
at some point (far above the transit frequency, i.e. 100s GHz, up to
THz). But I don't know how to deal with that. When I just keep all the
Fourier coefficients which fit into the 25GHz, the signal still looks
very "sinusoid"

Thanks,
Peter

```
```Hi,

aliasing sounds likely. A square wave switch decays with 1/k, where k is
the harmonic index (k = 1 is fundamental).

It is unusual to simulate RF at the actual carrier frequency. Instead,
complex baseband-equivalent signals are the typical workhorse.
If I need a harmonic, I would probably calculate its baseband signal to
avoid the vast stretch of empty spectrum.

What you could try easily is to use only fundamental and 3rd harmonic in a
continuous (non-switching) mixer/multiplication instead of the hard
switching.

_____________________________
Posted through www.DSPRelated.com
```
```On Tue, 15 Jul 2014 16:20:09 -0700, Peter Mairhofer wrote:

> Hi,
>
> I simulate (or want to simulate) an RF system. My simulation Nyquist
> rate is 50GHz, the signals are 8 Msamples long and there is a 5MHz
> transmission at 1GHz (using standard I/Q modulation).

<< much snipped >>

Nyquist didn't say anything about a "simulation Nyquist rate".  What do
you really mean?

http://wescottdesign.com/articles/Sampling/sampling.pdf

I think that your problem is that you are trying to simulate the behavior
of square waves in a sampled-time system.  Because square waves have such
rich harmonic content, you WILL have problems.

I find it best to analyze the behavior of the RF circuit at the carrier
frequency with pencil and paper, and leave the simulation for the IF or
baseband.

If you feel you absolutely must do this with square waves, then take the
square waves and filter them so that they do not alias within your chosen
simulation sampling rate (this is kind of Mnentwig's suggestion, only
carried out to more harmonics).

But really, the reason that God did not make pencils and paper disappear
the instant that we had Matlab is because He is merciful, and we still
need them.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

```
```On Wednesday, July 16, 2014 11:20:09 AM UTC+12, Peter Mairhofer wrote:
> Hi,
>
>
When you simulate a sine waveform you need to do

sin(2 pi (f/fs) k)

where fs is your sampling frequency (anything you like), f the actual frequency and k the  time index. In this way your signal frequency cannot be above fs/2.
```
```Tim Wescott <tim@seemywebsite.really> writes:
> [...]
> But really, the reason that God did not make pencils and paper disappear
> the instant that we had Matlab is because He is merciful, and we still
> need them.

AMEN brother!
--
Randy Yates
Digital Signal Labs
http://www.digitalsignallabs.com
```
```On 7/16/14 10:20 PM, Randy Yates wrote:
> Tim Wescott<tim@seemywebsite.really>  writes:
>> [...]
>> But really, the reason that God did not make pencils and paper disappear
>> the instant that we had Matlab is because He is merciful, and we still
>> need them.
>
> AMEN brother!

i don't belong to the sect of pencil heresy.

strictly ink, as God Herself intended.

--

r b-j                  rbj@audioimagination.com

"Imagination is more important than knowledge."

```
```On Wed, 16 Jul 2014 23:13:14 -0400, robert bristow-johnson wrote:

> On 7/16/14 10:20 PM, Randy Yates wrote:
>> Tim Wescott<tim@seemywebsite.really>  writes:
>>> [...]
>>> But really, the reason that God did not make pencils and paper
>>> disappear the instant that we had Matlab is because He is merciful,
>>> and we still need them.
>>
>> AMEN brother!
>
> i don't belong to the sect of pencil heresy.
>
> strictly ink, as God Herself intended.

Doing computations in pen and ink implies that you think you are too good
to ever mess up and need to erase.  This erroneous assumption is due to
arrogance, which is the Devil's own emotion.

SINNER!

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

```
```On 7/17/14 1:41 PM, Tim Wescott wrote:
> On Wed, 16 Jul 2014 23:13:14 -0400, robert bristow-johnson wrote:
>
>> On 7/16/14 10:20 PM, Randy Yates wrote:
>>> Tim Wescott<tim@seemywebsite.really>   writes:
>>>> [...]
>>>> But really, the reason that God did not make pencils and paper
>>>> disappear the instant that we had Matlab is because He is merciful,
>>>> and we still need them.
>>>
>>> AMEN brother!
>>
>> i don't belong to the sect of pencil heresy.
>>
>> strictly ink, as God Herself intended.
>
> Doing computations in pen and ink implies that you think you are too good
> to ever mess up and need to erase.

no, i just am committed to the mess up and mistakes.  then i start anew,
laying aside the old method on the wayside.  clean slate.

>  This erroneous assumption is due to
> arrogance, which is the Devil's own emotion.
>
> SINNER!

never denied that!

--

r b-j                  rbj@audioimagination.com

"Imagination is more important than knowledge."

```
```Tim Wescott <tim@seemywebsite.really> wrote:

(snip, someone wrote)
>> strictly ink, as God Herself intended.

> Doing computations in pen and ink implies that you think you
> are too good to ever mess up and need to erase.  This
> erroneous assumption is due to arrogance, which is the
> Devil's own emotion.

I do many things in pen (ball point, not with ink in bottles)
that might have mistakes.  If I make a mistake, then cross it out.

About the only thing that I specifically do in pencil is
logic schematics. Too many changes, and they look too ugly
crossed out.  Maybe analog schematics, but more often in pen.

I do crossword puzzles with a pen, try not to put in a word
until I am pretty sure, but don't mind crossing out and writing
(in smaller letters) another word. Not that I am that good. I can
usually do the Monday New York Times puzzle, hardly ever Friday,
and maybe sometimes Wednesday. But then again, I don't worry about
it if I can't do it.

For one, I like pens better, but maybe also it is a little more
incentive to try to get it right the first time.

-- glen
```
```On Thu, 17 Jul 2014 12:41:21 -0500, Tim Wescott
<tim@seemywebsite.really> wrote:

>On Wed, 16 Jul 2014 23:13:14 -0400, robert bristow-johnson wrote:
>
>> On 7/16/14 10:20 PM, Randy Yates wrote:
>>> Tim Wescott<tim@seemywebsite.really>  writes:
>>>> [...]
>>>> But really, the reason that God did not make pencils and paper
>>>> disappear the instant that we had Matlab is because He is merciful,
>>>> and we still need them.
>>>
>>> AMEN brother!
>>
>> i don't belong to the sect of pencil heresy.
>>
>> strictly ink, as God Herself intended.
>
>Doing computations in pen and ink implies that you think you are too good
>to ever mess up and need to erase.  This erroneous assumption is due to
>arrogance, which is the Devil's own emotion.
>
>SINNER!

Hi Tim
Pencils are ol'-fashioned, and I'm a high tech
guy.  The only thing I use a pencil for is to rewind
the magnetic tape back around the take-up reel
of my audio cassette tapes.

[-Rick-]
```