Accelerating the pace of engineering and science

# Analytical Coefficients of Harmonic Frequency Combinations

This example extracts closed-form solutions for the coefficients of frequencies in an output signal. The output signal results from passing an input through an analytical nonlinear transfer function.

This example uses the following Symbolic Math Toolbox capablities:

## Motivation

To motivate the solution, we take a simple element from circuit theory: an ideal diode (in forward bias operation). The current, I, is the output that depends exponentially on the input, V. Diodes have found use in creating devices such as mixers and amplifiers where understanding the harmonic structure of the output can be useful in characterizing the device and meeting design specifications.

```syms Is V Vo real;
I = Is*(exp(V/Vo) - 1)
```
```
I =

Is*(exp(V/Vo) - 1)

```

If V is a linear combination of 2 signals at frequencies LO and RF, the nonlinear transfer function will mix LO and RF to create output with content at combinatorial harmonic frequency combinations: freqs = {LO, 2LO, RF, 2RF, LO-RF, LO-2RF,...}.

The objective of this example is to determine the coefficients of freqs in the output.

## Define Space of Harmonic Frequency Combinations

Below, harmCombinations is a combinatorial combination of the integer multiples of the input frequencies LO and RF. We restrict the space of interest defined by 3 harmonics each in the LO and RF directions.

```n = 3;
harmCombinations = [kron((0:n)',ones(n*2+1,1)),repmat((-n:n)',n+1,1)];
syms LO RF real;
freqs = harmCombinations*[LO;RF];
```

The first n frequencies are just the negative harmonic frequencies and are therefore redundant considering that the input signal is real.

```freqs = freqs(n+1:end)
```
```
freqs =

0
RF
2*RF
3*RF
LO - 3*RF
LO - 2*RF
LO - RF
LO
LO + RF
LO + 2*RF
LO + 3*RF
2*LO - 3*RF
2*LO - 2*RF
2*LO - RF
2*LO
2*LO + RF
2*LO + 2*RF
2*LO + 3*RF
3*LO - 3*RF
3*LO - 2*RF
3*LO - RF
3*LO
3*LO + RF
3*LO + 2*RF
3*LO + 3*RF

```

## Taylor Expansion

To cover the frequency spectrum of interest, a Taylor series of order four for I(V) is sufficient.

```s = taylor(I, V, 'Order', 4)
```
```
s =

(Is*V^2)/(2*Vo^2) + (Is*V^3)/(6*Vo^3) + (Is*V)/Vo

```

Use an input signal combination of the LO and RF frequencies and express f in terms of cos(LO*t) and cos(RF*t).

```syms c1 c2 t real;
f0 = subs(s, V, c1*cos(LO*t) + c2*cos(RF*t));
f = expand(f0);
pretty(f)
```
```     2           3          3        2           3          3
Is c1  #2   Is c1  cos(LO t)    Is c2  #1   Is c2  cos(RF t)
--------- + ----------------- + --------- + -----------------
2               3               2               3
2 Vo            6 Vo            2 Vo            6 Vo

Is c1 cos(LO t)   Is c2 cos(RF t)   Is c1 c2 cos(LO t) cos(RF t)
+ --------------- + --------------- + ----------------------------
Vo                Vo                        2
Vo

2                     2
Is c1 c2  cos(LO t) #1   Is c1  c2 #2 cos(RF t)
+ ---------------------- + ----------------------
3                        3
2 Vo                     2 Vo

where

2
#1 == cos(RF t)

2
#2 == cos(LO t)

```

Rewrite f in terms of single powers of cosines.

```f = combine(f, 'sincos');
pretty(f)
```
```     2        2                                            2
Is c1    Is c2    Is c1 cos(LO t)   Is c2 cos(RF t)   Is c1  cos(2 LO t)
------ + ------ + --------------- + --------------- + ------------------
2        2          Vo                Vo                    2
4 Vo     4 Vo                                               4 Vo

3                  3                    2
Is c1  cos(LO t)   Is c1  cos(3 LO t)   Is c2  cos(2 RF t)
+ ---------------- + ------------------ + ------------------
3                   3                    2
8 Vo               24 Vo                 4 Vo

3                  3                       2
Is c2  cos(RF t)   Is c2  cos(3 RF t)   Is c1 c2  cos(LO t)
+ ---------------- + ------------------ + -------------------
3                   3                    3
8 Vo               24 Vo                 4 Vo

2
Is c1  c2 cos(RF t)   Is c1 c2 cos(LO t + RF t)
+ ------------------- + -------------------------
3                        2
4 Vo                     2 Vo

2
Is c1 c2 cos(LO t - RF t)   Is c1 c2  cos(LO t - 2 RF t)
+ ------------------------- + ----------------------------
2                             3
2 Vo                          8 Vo

2                           2
Is c1 c2  cos(LO t + 2 RF t)   Is c1  c2 cos(2 LO t + RF t)
+ ---------------------------- + ----------------------------
3                              3
8 Vo                           8 Vo

2
Is c1  c2 cos(2 LO t - RF t)
+ ----------------------------
3
8 Vo

```

## Extract and Display Coefficients

Get the non-constant i.e. non-DC harmonic frequency terms of the form cos(freq*t).

```cosFreqs = cos(expand(freqs*t));
terms = setdiff(cosFreqs', sym(1));
```

Extract the coefficients for all harmonic frequency terms including DC.

```[cx, tx] = coeffs(f, terms);
cx = simplify(cx);
```

Display the coefficients using table, T. Use cosFreqs as a row identifier.

```cosFreqs = arrayfun(@char,cosFreqs,'UniformOutput',false);
Frequencies = arrayfun(@char,freqs,'UniformOutput',false);
Coefficients = num2cell(zeros(size(freqs)));
T = table(Frequencies,Coefficients,'RowNames',cosFreqs);
```

Assign cx to the appropriate rows of T corresponding to the cosine terms of tx.

```nonzeroCosFreqs = arrayfun(@char,tx,'UniformOutput',false).';
T(nonzeroCosFreqs,'Coefficients') = arrayfun(@char,cx,'UniformOutput',false).';
```

Now, remove row names as they are redundant.

```T.Properties.RowNames = {};
```

Observe that the expressions for the terms are symmetric in LO and RF.

```T
```
```T =

Frequencies                    Coefficients
_____________    ___________________________________________

'0'              '(Is*(c1^2 + c2^2))/(4*Vo^2)'
'RF'             '(Is*c2*(8*Vo^2 + 2*c1^2 + c2^2))/(8*Vo^3)'
'2*RF'           '(Is*c2^2)/(4*Vo^2)'
'3*RF'           '(Is*c2^3)/(24*Vo^3)'
'LO - 3*RF'      [0]
'LO - 2*RF'      '(Is*c1*c2^2)/(8*Vo^3)'
'LO - RF'        '(Is*c1*c2)/(2*Vo^2)'
'LO'             '(Is*c1*(8*Vo^2 + c1^2 + 2*c2^2))/(8*Vo^3)'
'LO + RF'        '(Is*c1*c2)/(2*Vo^2)'
'LO + 2*RF'      '(Is*c1*c2^2)/(8*Vo^3)'
'LO + 3*RF'      [0]
'2*LO - 3*RF'    [0]
'2*LO - 2*RF'    [0]
'2*LO - RF'      '(Is*c1^2*c2)/(8*Vo^3)'
'2*LO'           '(Is*c1^2)/(4*Vo^2)'
'2*LO + RF'      '(Is*c1^2*c2)/(8*Vo^3)'
'2*LO + 2*RF'    [0]
'2*LO + 3*RF'    [0]
'3*LO - 3*RF'    [0]
'3*LO - 2*RF'    [0]
'3*LO - RF'      [0]
'3*LO'           '(Is*c1^3)/(24*Vo^3)'
'3*LO + RF'      [0]
'3*LO + 2*RF'    [0]
'3*LO + 3*RF'    [0]

```

## Verify Coefficients

As shown below, the output waveform is reconstructed from the coefficients and has an exact match with the output.

```simplify(f0 - (dot(tx,cx)))
```
```
ans =

0

```