Vectors Library

mikroPascal PRO for dsPIC30/33 and PIC24 includes a library for working and using vectors. All routines work with fractional Q15 format.

Library Routines

Vector_Set

Prototype

procedure Vector_Set(var input: array[1024] of word; size, value: word);

Description

Sets size elements of input to value, starting from the first element.

Parameters
  • input: pointer to original vector
  • size: number of vector elements
  • value: value written to the elements
Returns

Nothing.

Requires

Nothing.

Example
var vec2 : array[3] of word;

Vector_Set(vec2, 3, 0x4000);
Notes
  • size must be > 0
  • Length of input is limited by available RAM

Vector_Power

Prototype

function Vector_Power(N: word; var Vector: array[1024] of word): word;

Description

Function returns result of power value (powVal) in radix point 1.15

Parameters
  • N: number elements in vector(s)
  • srcV: pointer to source vector
Returns

Requires

Nothing.

Example
var vec1 : array[3] of word;

Vector_Power(3, vec1);
Notes
  • [W0..W2] used, not restored
  • [W4] used, not restored
  • AccuA used, not restored
  • CORCON saved, used, restored

Vector_Subtract

Prototype

procedure Vector_Subtract(var dest, v1, v2: array[1024] of word; numElems: word);

Description

This function does subtraction of two vectors.

dstV[n] = v1[n] - v2[n], n Î [0, numElems-1]

Parameters
  • numElems: must be less or equal to minimum size of two vectors.
  • v1: first vector
  • v2: second vector
  • dest: result vector
Returns

Nothing.

Requires

Nothing.

Example
var vec1      : array[3] of word;
    vec2      : array[3] of word;
    vecDest   : array[3] of word;

Vector_Subtract(vecDest, vec1, vec2, 3);
Notes
  • AccuA used, not restored.
  • CORCON saved, used, restored.

Vector_Scale

Prototype

procedure Vector_Scale(N: word; ScaleValue: integer; var SrcVector, DestVector: array[1024] of word);

Description

This function does vector scaling with scale value.

dstV[n] = sclVal * srcV[n], n Î [0, numElems-1]

Parameters
  • N: buffer length
  • SrcVector: original vector
  • DestVector: scaled vector
  • ScaleValue: scale value
Returns

Nothing.

Requires

Nothing.

Example
var vec1      : array[3] of word;
    vecDest   : array[3] of word;

Vector_Scale(3, 2, vec1, vecDest);
Notes
  • [W0..W5] used, not restored
  • AccuA used, not restored
  • CORCON saved, used, restored

Vector_Negate

Prototype

procedure Vector_Negate(var srcVector, DestVector: array[1024] of word; numElems: word);

Description

This function does negation of vector.

dstV[n] = (-1)*srcV1[n] + 0, n Î [0, numElems)

Parameters
  • srcVector: original vector
  • destVector: result vector
  • numElems: number of elements in vector(s)
Returns

Nothing.

Requires

Nothing.

Example
var vec1      : array[3] of word;
    vecDest   : array[3] of word;

Vector_Negate(vec1, vecDest, 3);
Notes
  • Negate of 0x8000 is 0x7FFF
  • [W0]..[W5] used, not restored
  • AccuA used, not restored
  • CORCON saved, used, restored

Vector_Multiply

Prototype

procedure Vector_Multiply(var v1, v2, dest: array[1024] of word; numElems: word);

Description

This function does multiplication of two vectors.

dstV[n] = srcV1[n] * srcV2[n], n Î [0, numElems-1]

Parameters
  • numElems: number elements in vector(s) (must be less or equal to minimum size of two vectors)
  • v1: first vector
  • v2: second vector
  • dest: result vector
Returns

Nothing.

Requires

Nothing.

Example
var vec1      : array[3] of word;
    vec2      : array[3] of word;
    vConDest  : array [10] of word;

Vector_Multiply(vec1, vConDest, vec2, 3); 
Notes
  • [W0..W5] used, not restored
  • AccuA used, not restored
  • CORCON saved, used, restored

Vector_Min

Prototype

function Vector_Min(var Vector: array[1024] of word; numElems: word; var MinIndex: word): word;

Description

This function finds minimal value in vector.

minVal = min (srcV[n]), n Î [0, numElems-1]

If srcV[i] = srcV[j] = minVal, and i < j, then MinIndex = j.

Parameters
  • Vector: original vector
  • numElems: number of elements in vector
  • MinIndex: index of minimum value
Returns

Minimum value (minVal).

Requires

Nothing.

Example
var vec1      : array[3] of word;
    index, rslt     : word;

rslt = Vector_Min(vec1, 3, index);
Notes [W0..W5] used, not restored

Vector_Max

Prototype

function Vector_Max(var Vector: array[1024] of word; numElems: word; var MaxIndex: word): word;

Description

This function find maximal value in vector.

maxVal = max (srcV[n]), n Î [0, numElems-1]

If srcV[i] = srcV[j] = maxVal, and i < j, then maxIndex = j.

Parameters
  • Vector: original vector
  • numElems: number of elements in vector(s)
  • MaxIndex: index of maximum value
Returns

Maximum value (maxVal).

Requires

Nothing.

Example
var vec1      : array[3] of word;
    index, rslt     : word;

rslt = Vector_Max(vec1, 3, index);
Notes [W0..W5] used, not restored

Vector_Dot

Prototype

function Vector_Dot(var v1, v2: array[1024] of word; numElems: word): word;

Description

Function calculates vector dot product.

Parameters
  • v1: first vector
  • v2: second vector
  • numElems: number of elements in vector(s)
Returns

Dot product value :

Requires

Nothing.

Example
var vec1 : array[3] of word;

rslt = Vector_Dot(vec1,vec1,3);
Notes
  • [W0..W2] used, not restored
  • [W4..W5] used, not restored
  • AccuA used, not restored
  • CORCON saved, used, restored

Vector_Correlate

Prototype

procedure Vector_Correlate(var v1, v2, dest: array[1024] of word; numElemsV1, numElemsV2: word);

Description

Function calculates Vector correlation (using convolution).


where:
x[n] defined for n Î [0, N)
y[n] defined for n Î [0, M), M £ N
r[n] defined for n Î [0, N+M-1)

Parameters
  • v1: first vector
  • v2: second vector
  • numElemsV1: number of the first vector elements
  • numElemsV2: number of the second vector elements
  • dest: result vector
Returns

Nothing.

Requires

Nothing.

Example
var vec1      : array[3] of word;
    vConDest  : array [10] of word;

Vector_Correlate(vec1,vec1,vConDest,3,3); 
Notes [W0..W7] used, not restored

Vector_Convolve

Prototype

procedure Vector_Convolve(var v1, v2, dest: array[1024] of word; numElemsV1, numElemsV2: word);

Description

Function calculates Vector using convolution.

, n Î [0, M)
, n Î [M, N)
, n Î [N, N+M-1)

Parameters
  • v1: first vector
  • v2: second vector
  • numElemsV1: number of the first vector elements
  • numElemsV2: number of the second vector elements
  • dest: result vector
Returns

Nothing.

Requires

Nothing.

Example
var vec1      : array[3] of word;
    vConDest2 : array[10] of word;

Vector_Convolve(vec1,vec1,vConDest2,3,3); 
Notes
  • [W0..W7] used, not restored
  • [W8..W10] saved, used, restored
  • AccuA used, not restored
  • CORCON saved, used, restored

Vector_Add

Prototype

procedure Vector_Add(var dest, v1, v2: array[256] of word; numElems: word);

Description

Function calculates vector addition.

dstV[n] = srcV1[n] + srcV2[n], n Î [0, numElems-1]

Parameters
  • v1: first vector
  • v2: second vector
  • numElemsV1: number of vector(s) elements
  • dest: result vector
Returns

Nothing.

Requires

Nothing.

Example
var vec1      : array[3] of word;
    vec2      : array[3] of word;
    vecDest   : array[3] of word;

Vector_Add(vecDest, vec1, vec2, 3);
Notes
  • [W0..W4] used, not restored
  • AccuA used, not restored
  • CORCON saved, used, restored
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code