UM0304 STMICROELECTRONICS | Alldatasheet
Document overview
- Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
- PDF pages: 19
Technical content
Datasheet sections
- 1 Definitions and relate d documents
- 1.1 Acronyms and terminology
- 1.2 ARM and Thumb
- 1.3 References
- 2 IIR ARMA 16-bit filter
- 2.1 Description
- 2.2 Function
- 2.3 Arguments and variables
- 2.3.1 Calling the function from C
- 2.3.2 Calling the function from assembly
- 2.4 Algorithm
- 2.5 Assembly code
- 2.6 Requirements
- 2.7 Implementation
- 2.8 Benchmarking
- 3 Block FIR 16-bit filter
- 3.1 Description
- 3.2 Function
- 3.3 Arguments and variables
- 3.3.1 Calling the function from C
- 3.3.2 Calling the function from Assembly
- 3.4 Algorithm
- 3.5 Assembly code
- 3.6 Requirements
- 3.7 Implementation
- 3.8 Benchmarking
- 4 Complex 16-bit radix-4 FFT
- 4.1 Description
- 4.2 Algorithm
STR91x DSP library (DSPLIB) Introduction This manual presents a library of ARM assembly source code modules for digital signal processing (DSP) applications such as infinite impulse response (IIR) filter, finite impulse response (FIR) filter and fast Fourier transform (FFT) applicable for a range of DSP applications including VSLP vocoder. These assembly source code modules are presented for ARM mode and have been tested in an ARM9E-based STR91x platform. In addition, the assembly source code modules have been tested in an IAR Workbench environment as well, but STMicroelectronics cannot guarantee that these assembly source code modules will be flawless for all applications. The algorithm modules are presented "as is with no warranty".
1 Definitions and related documents
1.1 Acronyms and terminology
1.2 ARM and Thumb
bit ARM instruction. However, not all ARM instructions are available in the Thumb subset. accomplished with a sequence of Thumb instructions. to switch the processor from executing instructions in one state to executing in the other. address specified in Rn. Thus, BX is absolute rather than PC-relative. All ARM instructions are word-aligned, and all Thumb instructions are half-word aligned. Table 1. Definition of acronyms and terms
UM0304 Definitions and related documents processor can actually use this bit to determine if the instruction jumped to should be executed in Thumb or ARM state:
- If bit 0 set then execute in Thumb state
- If bit 0 clear then execute in ARM state Thumb was defined for two main reasons: 1. Better code density, as the instructions are half the size of ARM instructions (although some ARM instructions require two Thumb instructions for the same effect). Y ou would have to compile the application for ARM and Thumb and see what gives the best result. 2. Better performance from narrow memory, as instruction fetches from smaller memory (ie: 8-bit or 16-bit) will be reduced in Thumb mode.
1.3 References
- Sanjit K. Mitra, "Digital Signal Processing - A Computer Based Approach", McGraw Hill, Third Edition 2006. 2. R. Deka and J. G. Gardiner, "On the Fundamentals of Digital Signal Processing Micros," Journal of Microcomputer Applications, Vol 17 No 1, pp 101-135, U K, January 1994. 3. E. Oran Brigham, "The Fast Fourier Transform and its Applications", ISBN 0-13- 307547-8, Prentice-Hall International Editions, 1988. 4. C.S. Burrus, "Unscrambling for fast DFT algorithms", IEEE Transactions on Acoustics, Speech, and Signal Processing, ASSP-36(7), 1086-1089, July 1988. Implementation", J. Wiley, 1985.
IIR ARMA 16-bit filter UM0304
2 IIR ARMA 16-bit filter
2.1 Description
The IIR filter function performs an ARMA filter with 4 auto-regressive filter coefficients and 5 moving-average filter coefficients respectively for ny output samples. This is a 16-bit fixed- point implementation. Reference [1] may be used to explore more about IIR filters.
2.2 Function
void iirarma_arm9e(void *y, void *x, short *h2, short *h1, int ny);
2.3 Arguments and variables
- Output array vector y[ny+4] (used in actual computation. first four elements must have the previous outputs. Thus the first output starts y[4] when ny = 0)
- Input array vector x[ny+4]
- Moving-average filter coefficients vector h2[5]
- Auto-regressive filter coefficients h1[5] and h1[0] are not used
- Number of output samples ny is a multiple of 4 and must be ≥ 8
2.3.1 Calling the function from C
Set the arguments and variables as appropriate in C main program and call the function. In the STR91x DSPLIB this is set in the 91x_dsp.h header file.
2.3.2 Calling the function from assembly
Use the following registers equivalent to arguments/variables.
- R0 to the address of output vector y[]
- R1 to the address of input vector x[]
- R2 to the address of coefficient vector h2[]
- R3 to the address of coefficient vector h1[]
- R12 to the address of ny Then use the BL instruction to call the function.
UM0304 IIR ARMA 16-bit filter
2.4 Algorithm
Following is the C equivalent of the assembly code. Note that the assembly code is hand optimized and restrictions may apply. C equivalent IIR ARMA algorithm iir_arma_arm9e(short *y, short *x, short *h2, short *h1, int ny) int i, j; int sum; for (i=0; i<ny; i++){ sum = h2[0] * x[4+i]; for (j = 1; j <= 4; j++) sum += h2[j]*x[4+i-j]-h1[j]*y[4+i-j];
2.5 Assembly code
The assembly code for this IIR ARMA algorithm is validated in STR91x environment for ARM966E-S. The assembly code is for 16-bit fixed point applications. The assembly source code module may be found in DSPLIB.
2.6 Requirements
The assembly module is little endian and written for ARM9E in ARM mode with stack aligned to 8 bytes. The module is for 16-bit fixed point applications where input data is expected to be 16-bit fixed point and it will produce 16-bit fixed-point outpute. A caller needs to organize an input vector x[] for filter input and output vector y[] for filter output then supply the filter coefficients h1[] as well as h2[]. The vector length for x[] and y[] needs to follow the following guidelines.
- ny is multiple of 4 and greater than or equal to 8
- Input data array x[ ] contains ny + 4 input samples to produce ny output samples.
2.7 Implementation
- The output vector y[] contains ny + 4 locations, but its first 4 data are not used, i.e., first output is y[4] while ny = 0.
- The inner loop that iterated through the filter coefficients is completely unrolled.
- The code is little ENDIAN.
- The code is interrupt-tolerant but not interruptible.
2.8 Benchmarking
clocking, while the STR91x engine runs at 96 MHz. Table 2. Benchmarking of IIR ARMA algorithm module
UM0304 Block FIR 16-bit filter
3 Block FIR 16-bit filter
3.1 Description
This function computes a direct-form real FIR filter using the coefficients stored in vector h[] using a simple Block FIR technique, and moves delay line. The input sequence needs to be start with (T -1) zeros. This is a 16-bit fixed-point implementation. Reference [1] may be used to explore more about FIR filters. The user needs to organize the output buffer for y[N] and needs to design the filter taps h[T] and organize the coefficients in reverse order. The users also need to scale the input x[M] and filter taps h[T] to avoid overflow. This function may be called by C or Assembly function(s).
3.2 Function
typedef struct coef{ short *h; unsigned int m; }nh; int fir_16by16_arm9e(int y[], short x[], sx *p, int N); nh p; p.h = h; p.M = T;
3.3 Arguments and variables
- h[T] = filter coefficient vector with T number of taps, an integer multiple of 6
- T = number of filter coefficients (taps), an integer multiple of 6
- N = filter length or vector length for output
- x[M] = filter input vector with total M samples, i.e., (M = N + T - 1)
- y[N] = filter output vector with total N samples
3.3.1 Calling the function from C
Set the arguments and variables as appropriate in C main program and call the function.
Block FIR 16-bit filter UM0304
3.3.2 Calling the f unction from Assembly
Use the following registers equivalent to arguments/variables.
- Move N to R3, N is output filter length or output vector length, a multiple of 6
- Move SP to R2, comparable &p as in C function above h[T] = filter coefficient vector with T number of taps, T is an integer multiple of 6
- Set R1 to the address of x, comparable as in x[M] filter input vector with total M samples, i.e., (M = N + T - 1)
- Set R0 to the address of y, comparable as in y[N] filter output vector with total N samples Then use BL instruction to call the function.
3.4 Algorithm
Following is the C equivalent of the assembly code. Note that the assembly code is hand optimized and restrictions may apply. Block FIR Filter Reference C Source void fir_16by16_arm9e(short input, int nt, short h[], short z[]) int j; short acc; /* store input at the beginning of the delay line */ z[0] = input; /* calc FIR */ acc = 0; for (j = 0; j < nt; j++) { acc += h[j] * z[j]; /* shift delay line */ for (j = nt - 2; j >= 0; j--) { z[j + 1] = z[j]; return acc;
3.5 Assembly code
The assembly code for this block FIR 16-bit fixed-point filter algorithm is validated in STR91x environment for ARM966E-S. The assembly code is for 16-bit fixed point applications, and
the filter coefficients are a multiple of 6 - more information is available in the source code. The source code module may be found in DSPLIB.
3.6 Requirements
Hamming, Hanning, and Blackman etc as required by the filter response. coefficients, T, must be an integer multiple of 6.
3.7 Implementation
- The filter needs T number of coefficients and T is multiple of 6
- The output vector y[N] is such that N equals (2 * T)
- The input vector x[M] is such that M equals (N + T - 1)
- The code is little ENDIAN
- The code is interrupt-tolerant but not interruptible
3.8 Benchmarking
clocking, while the STR91x engine runs at 96 MHz. Table 3. Benchmarking of Block FIR algorithm module
Complex 16-bit radix-4 FFT UM0304
4 Complex 16-bit radix-4 FFT
4.1 Description
The DFT X[k] of a complex sequence x[n] of length N is calculated by: X[k] = S n=0 N-1 x[n]*exp(-j2pnk/N) for k=0, 1,2 0.N-1 A direct calculation of N complex values of X[k] will require 4N2 multiplications and 4N(N-1) additions given the trigonometric function values. For example, if N=128, 65536 multiplications and 65024 additions are required. In this report, a radix-4 FFT algorithm is implemented. More details about FFT algorithms including radix-4 are found in references [3] [4] and [5].
4.2 Algorithm
The algorithm works as follows: Block 1: Bit reverse Copy the data from the input buffer to the output buffer in bit-reversed order. It is an integer between 0 and N-1, with binary representation as shown, for the bit reversal of k, we will write. So we perform the equivalent of the following loop: int k, khat, bit; for (k=0, khat=0; k<N; k++) { X[khat]=x[k]; for (bit=N/2; (khat & bit)!=0; bit >>=1) khat ^= bit; khat ^= bit; /* finish incrementing khat */ The bit loop inside increments khat as a bit reversed number. If the input buffers and output buffers are equal (X=x), more care needs to be taken to do the action in place, but it can be performed faster as fewer elements need to be moved. Putting the elements in bit reversed order has the effect of grouping together all the Ys and Zs of the previous subsection so no further rearrangement needs to be done.
- denotes complex multiplication # define pi 3.14159265358 for (n=2; n<=N; n <<= 1) { w=2*pi/n; for (m=0; m<N; m+=n) { for (k=0; k<n/2; k++) { y=X[m+k]; z=X[m+k+n/2] * exp(-ikw); X[m+k]=(y+z)/2; X[m+k+n/2]=(y-z)/2; After n=2 we have performed N/2 two-element FFTs, positioned at offsets m=0, 2, 4, ... N-2. After n=4 we have performed N/4 four-element FFTs positioned at offset m=0, 4, 8, … N-4. After n=N we are left with the answer to the main FFT in the buffer X. k bN 1 - ... b2 ()?= 2 Because each pass of the FFT divides the data by 4 (radix4 passes) there is no bit growth. Four cases were tested as shown in Table 4.
Table 4. Bit growth of FFT routine
4.3 Arguments and variables
- A pointer y to the output buffer for the transformed array to be stored. This buffer is the same in size as the input buffer x, with same order as in input buffer for the real part as well as the imaginary part.
- An integer nBin giving the base 2 logarithm of the number of points N in the Fourier Transform.
4.4 Function
and it imaginary part x[3]; and so on … Similarly, the output is also in the same order. The block outline of this FFT algorithm is shown in Table 5.
4.4.1 Calling the FFT function from C
Table 5. Block outline of FFT routine
- The buffers x and y may coincide. In this case the FFT is said to be done in place rather than out of place.
- To prevent overflow within the algorithm, the real and imaginary values in the array x should be sign extended 16-bit quantities (between -32768 and +32767).
- The values of N allowed are 64,256, 1024.
4.4.2 Calling the FFT function from assembly
- R0 to the address of the input buffer x
- R1 to the address of the output buffer y
- R2 to N Call the FFT routine using BL FFT. On exit R0 will contain the exit code (0 if successful), R1- R3 and R14 will have been corrupted and R4-R13 preserved.
4.5 The FFT function characteristics
Table 6. The FFT function characteristics
between the labels FFT and FFTSTART. The second stage begins at the label FFTSTART.
4.6 Performance benchmarking
Table 7. Benchmarking of Radix-4 Complex FFT Algorithm: STR91x 96 MHz.
64 Point
256 Point
1024 Point
4.7 Fixed-point error benchmarking
floating-point and fixed-point C function, and amplitude, for a 16-point FFT. Table 8. The FFT function fixed-point error benchmarking
5 Revision history
Table 9. Document revision history 09-Jun-2008 3 Removed references to obsolete products.