# seqperiod

Compute period of sequence

## Description

## Examples

### Multichannel Signal Periods

Generate a multichannel signal and determine the period of each column.

x = [4 0 1 6; 2 0 2 7; 4 0 1 5; 2 0 5 6]; p = seqperiod(x)

`p = `*1×4*
2 1 4 3

The first column of `x`

has period 2. The second column of `x`

has period 1. The third column of `x`

is not periodic, so `p(3)`

is just the number of rows of `x`

. The fourth column of `x`

has period 3, although the second repetition of the periodic sequence is incomplete.

Compute the number of times that each periodic sequence is repeated.

[~,nr] = seqperiod(x)

`nr = `*1×4*
2.0000 4.0000 1.0000 1.3333

In the first column of `x`

, the periodic sequence appears twice. In the second column, the one-sample sequence is repeated as many times as there are samples. In the third column, there is no repetition. The number of repetitions in the fourth column is one plus the fraction of the sequence length represented by the remaining sample.

### Periods of Two-Channel Sinusoid

Generate a two-channel sinusoid such that one channel has four periods in the sampling interval and the other channel has two periods. Plot the sinusoid.

n = 0:31; x = cos(2*pi./[8;16].*n)'; plot(n,x,'.-') axis tight

Compute the lengths of the repeated subsequences and the number of repetitions. Specify an absolute tolerance of `1e-5`

.

[p,nr] = seqperiod(x,1e-5)

`p = `*1×2*
8 16

`nr = `*1×2*
4 2

### Sequence Period Along Higher Dimension

Create an array whose first two dimensions have size 1. Along the third dimension, the array has a repeating sequence.

a = permute([5 4 3 5 4 3 5 4],[3 1 2])

a = a(:,:,1) = 5 a(:,:,2) = 4 a(:,:,3) = 3 a(:,:,4) = 5 a(:,:,5) = 4 a(:,:,6) = 3 a(:,:,7) = 5 a(:,:,8) = 4

Compute the period of the repeating sequence and the number of repetitions contained in the array. The function works along the third dimension, as expected.

[p,nr] = seqperiod(a)

p = 3

nr = 2.6667

## Input Arguments

`x`

— Input array

vector | matrix | *N*-D array

Input array, specified as a vector, matrix, or *N*-D array.

If

`x`

is a matrix, then`seqperiod`

checks for periodicity along each column of`x`

.If

`x`

is a multidimensional array, then`seqperiod`

checks for periodicity along the first array dimension of`x`

with size greater than 1.

The length of `x`

does not have to be a multiple of
`p`

, so that incomplete repetitions are permitted at the end of
`x`

.

**Example: **`sin(pi./[4;2]*(0:159))'`

specifies a two-channel sinusoid.
The second channel has twice the frequency of the first channel.

**Data Types: **`double`

`tol`

— Absolute tolerance

`1e-10`

(default) | positive real scalar

Absolute tolerance to determine when two numbers are close enough to be treated as equal, specified as a positive real scalar.

**Data Types: **`double`

## Output Arguments

`p`

— Sequence period

scalar | vector | matrix | *N*-D array

Sequence period, returned as a scalar, vector, matrix, or *N*-D
array. If a sequence is not periodic, then `p`

equals the length of
`x`

along the chosen dimension.

If

`x`

is a matrix, then`p`

is a row vector with the same number of columns as`x`

.If

`x`

is a multidimensional array, then`p`

is a multidimensional array of integers whose first dimension is of size 1. The remaining dimensions of`p`

correspond to the remaining dimensions of`x`

with sizes larger than 1.

`nr`

— Number of sequence repetitions

vector | matrix | *N*-D array

Number of sequence repetitions, returned as a scalar, vector, matrix, or
*N*-D array. `nr`

has the same dimensions as
`p`

. The elements of `nr`

are not necessarily
integers.

## Version History

**Introduced before R2006a**

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)