# fourierBasis

Fourier basis functions for tunable gain surface

## Syntax

``shapefcn = fourierBasis(N)``
``shapefcn = fourierBasis(N,nvars)``
``shapefcn = fourierBasis(___,varnames)``

## Description

You use basis function expansions to parameterize gain surfaces for tuning gain-scheduled controllers. `fourierBasis` generates periodic Fourier series expansions for parameterizing gain surfaces that depend periodically on the scheduling variables, such as a gain that varies with angular position. Use the output of `fourierBasis` to create tunable gain surfaces with `tunableSurface`.

example

````shapefcn = fourierBasis(N)` generates a function that evaluates the first `N` harmonics of eiπx:$F\left(x\right)=\left[\mathrm{cos}\left(\pi x\right),\mathrm{sin}\left(\pi x\right),\text{\hspace{0.17em}}\mathrm{cos}\left(2\pi x\right),\mathrm{sin}\left(2\pi x\right),\text{\hspace{0.17em}}\dots ,\mathrm{cos}\left(N\pi x\right),\mathrm{sin}\left(N\pi x\right)\right].$F is the function represented by `shapefcn`. The term of F are the first `2*N` basis functions in the Fourier series expansion of a periodically varying gain, K(x), with K(–1) = K(1). That expansion is given by:$K\left(x\right)=\frac{{a}_{0}}{2}+\sum _{k}\left\{{a}_{k}\mathrm{cos}\left(k\pi x\right)+{b}_{k}\mathrm{sin}\left(k\pi x\right)\right\}.$```

example

````shapefcn = fourierBasis(N,nvars)` generates an `nvars`-dimensional Fourier basis for periodic functions on the region [–1,1]nvars. This basis is the outer product of `nvars` Fourier bases with `N` harmonics along each dimension. The resulting function `shapefcn` takes `nvars` input arguments and returns a vector with `(2*N+1)^(nvars-1)-1` entries. To specify basis functions of multiple scheduling variables where the expansions are different for each variable, use `ndBasis`.```
````shapefcn = fourierBasis(___,varnames)` specifies variable names. Use this syntax with any of the previous syntaxes to name the variables in `shapefcn`. Using variable names improves readability of the `tunableSurface` object display and of any MATLAB® code you generate using `codegen`. ```

## Examples

collapse all

Create basis functions for a gain that varies as a periodic function of one scheduling variable.

`shapefcn = fourierBasis(2);`

`shapefcn` is a handle to a function of one variable that returns an array of four values corresponding to the first two harmonics of a periodic function on x = [–1,1]:

`$F\left(x\right)=\left[\mathrm{cos}\left(\pi x\right),\mathrm{sin}\left(\pi x\right),\phantom{\rule{0.2777777777777778em}{0ex}}\mathrm{cos}\left(2\pi x\right),\mathrm{sin}\left(2\pi x\right)\right].$`

Use `shapefcn` as an input argument to `tunableSurface` to define a gain surface of the form:

`$K\left(x\right)={K}_{0}+{K}_{1}\mathrm{cos}\left(\pi x\right)+{K}_{2}\mathrm{sin}\left(\pi x\right)+{K}_{3}\mathrm{cos}\left(2\pi x\right)+{K}_{4}\mathrm{sin}\left(2\pi x\right).$`

The variable x is a normalized version of the scheduling variable for your tunable surface. Because the basis functions created by `fourierBasis` act on normalized variables, your gain-scheduled system must use design points whose endpoint values delineate exactly one period. For example, suppose you use the following design points:

```alpha = [-7,-4,-1,2,5]; domain = struct('alpha',alpha); K = tunableSurface('K',0,domain,shapefcn);```

In normalizing the domain, the software assumes that the gain surface, `K`, is periodic in `alpha` such that `K(-7)` = `K(5)`.

Create a two-dimensional Fourier basis for periodic functions of x and y on the domain ${\left[-1,1\right]}^{N}$. The basis functions should go up to the third harmonic in both the x and y dimensions.

`F2D = fourierBasis(3,2);`

This function is the outer product of two vectors:

```x = fourierBasis(3); y = fourierBasis(3);```

Equivalently, you can obtain the outer product using ndBasis.

```F = fourierBasis(3); F2D = ndBasis(F,F);```

The values in the vector returned by `F` include cross-terms such as $\mathrm{sin}\left(\pi x\right)\mathrm{cos}\left(\pi y\right)$ and $\mathrm{sin}\left(3\pi x\right)\mathrm{cos}\left(2\pi y\right)$.

## Input Arguments

collapse all

Number of harmonics of Fourier expansion, specified as a positive integer.

Number of scheduling variables, specified as a positive integer.

Variable names in the generated function `shapefcn`, specified as a:

• Character vector, for monovariable basis functions.

• Cell array of character vectors, for multivariable basis functions.

If you do not specify `varnames`, then the variables in `shapefcn` are named `{'x1','x2',...}`.

Example: `{'alpha','V'}`

## Output Arguments

collapse all

Fourier expansion, specified as a function handle. `shapefcn` takes as input arguments the number of variables specified by `nvars`. It returns a vector of polynomials in those variables, defined on the interval [–1,1] for each input variable. When you use `shapefcn` to create a gain surface, `tunableSurface` automatically generates tunable coefficients for each polynomial term in the vector.

## Tips

• If the gain surface `K` is periodic in the scheduling variable x with period P, make sure that the corresponding entry in `K.Normalization.InputScaling` is set to P/2 to ensure consistency with the `fourierBasis` period, P = 2. When using the default normalization, the x values in `K.SamplingGrid` must span exactly one period, [a, a+P], to satisfy this requirement. See the `Normalization` property of `tunableSurface` for more details.

## Version History

Introduced in R2015b