RM0020 STMICROELECTRONICS | Alldatasheet
Document overview
- Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
- PDF pages: 69
Technical content
Datasheet sections
- 1 Library functions
- 1.1 FFT
- 1.2 Pressure sensing
- 1.3 Image
- 1.4 Filter
- 1.5 Macros
- 2 Supported compilers
- 3 Directory structure
- 4 How to use the library in a project
- 5 Example projects
- 6 Function API
- 6.1 Bit reversal permutation for 16-bit data
- 6.2 Bit reversal permutation for 32-bit data
- 6.3 N-point radix-4 complex to complex float in-place FFT
- 6.4 N-point radix-4 complex to complex frac16/frac32 in-place FFT
- 6.5 N-point quad radix-2 complex to complex float in-place FFT
- 6.6 N-point quad radix-2 complex to complex frac16/frac32 in-place FFT
- 6.7 Last stage of N-point radix-2 complex to complex float in-place FFT
- 6.9 Split function of N-point real to complex float FFT
- 6.10 Split function of N-point real to complex frac32 FFT
- 6.11 Complex float windowing function
- 6.12 Complex frac16 windowing function
- 6.13 Real float windowing function
- 6.14 Real frac16 windowing function
SPC56xx DSP function library 2 Introduction The SPC56xx DSP function library 2 contains optimized functions for SPC56xx family of processors with Signal Processing Engine (SPE APU).
6.30 iir_frac16_2nd_hc - frac16 second-order IIR filter with half coefficients . . 55
1 Library functions
The library functions are presented in the following sections.
1.1 FFT
- bitrev_table_16bit - Bit Reversal Permutation for 16-bit data (frac16)
- bitrev_table_32bit - Bit Reversal Permutation for 32-bit data (frac32 and float)
- fft_radix4_float - N-point radix-4 complex to complex float in-place FFT, N is even power of two
- fft_radix4_frac32 - N-point radix-4 complex to complex frac16/frac32 in-place FFT, N is even power of two
- fft_quad_float - N-point quad radix-2 complex to complex float in-place FFT, N is even power of two
- fft_quad_frac32 - N-point quad radix-2 complex to complex frac16/frac32 in-place FFT, N is even power of two
- fft_radix2_last_stage_float - calculates the last stage of N-point radix-2 complex to complex float in-place FFT, together with fft_quad_float function is used to calculate N-point complex to complex float in-place FFT where N is odd power of two
- fft_radix2_last_stage_frac32 - calculates the last stage of N-point radix-2 complex to complex frac32 in-place radix-2 FFT, together with fft_quad_frac32 function is used to calculate N-point complex to complex in-place frac16/frac32 FFT where N is odd power of two
- fft_real_split_float - split function for N-point real to complex float FFT
- fft_real_split_frac32 - split function for N-point real to complex frac32 FFT
- window_apply_complex_float - complex float windowing function
- window_apply_complex_frac16 - complex frac16 windowing function
- window_apply_real_float - real float windowing function
- window_apply_real_frac16 - real frac16 windowing function
1.2 Pressure sensing
- mfb50_pmh - calculates mass fraction burned (MFB), MFB50 value and PMH index
- mfb50_index - calculates MFB50 position index
1.3 Image
- conv3x3 - 2-D convolution with 3x3 kernel
- sobel3x3 - sobel filter
- sobel3x3_horizontal - horizontal sobel filter
- sobel3x3_vertical - vertical sobel filter
1.4 Filter
- corr_frac16 - frac16 correlation function
- fir_float - float FIR filter
- fir_frac16 - frac16 FIR filter
- iir_float_1st - float first-order IIR filter
- iir_float_2nd - float second-order IIR filter
- iir_float_casc - cascade of float second-order IIR filters
- iir_frac16_1st - frac16 first-order IIR filter
- iir_frac16_2nd - frac16 second-order IIR filter
- iir_frac16_casc - cascade of frac16 second-order IIR filters
- iir_frac16_2nd_hc - frac16 second-order IIR filter with half coefficients
1.5 Macros
The library defines macros in libdsp2.h that encapsulate some of the previous functions to allow easy usage; see the libdsp2.h file and the examples in example directory.
Supported compilers RM0020
2 Supported compilers
The library was built and tested using the following compilers:
- CodeWarrior for PowerPC V1.5 beta2
- Green Hills MULTI for PowerPC v4.2.1
- Wind River Compiler Version 5.2.1.0
RM0020 Directory structure
3 Directory structure
- doc - contains library user's manual
- example - contains library example projects for Axiom-0321 MPC5554 development board, for each supported compiler
- include - contains library header file libdsp2.h
- src - contains library source files for CodeWarrior compiler and C source files
- src\\src_GHS - contains library source files for Green Hills compiler
- src\\src_WR - contains library source files for Wind River compiler
How to use the library in a project RM0020
4 How to use the library in a project
- CodeWarrior – add library source files with required functions into your project window – add path to library include file libdsp2.h to “Target Settings (Alt-F7)->Access Paths->User Paths” – include file libdsp2.h into your source file
- Green Hills – add library source files with required functions into your project window – use -I compiler option -I{path to libdsp2.h}, – include file libdsp2.h into your source file
- Wind River – add library source files with required functions into your project window – use -I compiler option -I{path to libdsp2.h} – include file libdsp2.h into your source file Code example: #include "libdsp2.h" #define N_MAX 512 float inout_buffer [2*N_MAX+8]; /* +8 to ensure there is 32 bytes of readable memory behind buffer, must be double-word aligned */ void main(void) { /* compute complex to complex float in-place FFT */ fft_quad_float_512(inout_buffer);
5 Example projects
The library contains ready to run example projects which are located in example directory. The projects are created for Axiom MPC5554 development board.
- CodeWarrior – CW_example.mcp - examples of float FFTs – CW_example1.mcp - examples of frac16/frac32 FFTs – CW_example2.mcp - examples of real to complex float FFTs – CW_example3.mcp - examples of real to complex frac16/frac32 FFTs – CW_example4.mcp - examples of real and complex float windowing functions – CW_example5.mcp - examples of real and complex frac16 windowing functions – CW_example6.mcp - examples of pressure sensing functions mfb50_pmh and mfb50_index – CW_example7.mcp - examples of 2D convolution with 3x3 kernel – CW_example8.mcp - examples of sobel filters – CW_example9.mcp - examples of frac16 data correlation and auto-correlation function – CW_example9a.mcp - examples of FIR filters – CW_example9b.mcp - examples of float data IIR filters – CW_example9c.mcp - examples of frac16 data IIR filters
- Green Hills – GHS_example.gpj - examples of float FFTs – GHS_example1.gpj - examples of frac16/frac32 FFTs – GHS_example2.gpj - examples of real to complex float FFTs – GHS_example3.gpj - examples of real to complex frac16/frac32 FFTs – GHS_example4.gpj - examples of real and complex float windowing functions – GHS_example5.gpj - examples of real and complex frac16 windowing functions – GHS_example6.gpj - examples of pressure sensing functions mfb50_pmh and mfb50_index – GHS_example7.gpj - examples of 2D convolution with 3x3 kernel – GHS_example8.gpj - examples of sobel filters – GHS_example9.gpj - examples of frac16 data correlation and auto-correlation function – GHS_example9a.gpj - examples of FIR filters – GHS_example9b.gpj - examples of float data IIR filters – GHS_example9c.gpj - examples of frac16 data IIR filters
- Wind River – makefile - examples of float FFTs – makefile1 - examples of frac16/frac32 FFTs – makefile2 - examples of real to complex float FFTs – makefile3 - examples of real to complex frac16/frac32 FFTs – makefile4 - examples of real and complex float windowing functions
– makefile5 - examples of real and complex frac16 windowing functions – makefile6 - examples of pressure sensing functions mfb50_pmh and mfb50_index – makefile7 - examples of 2D convolution with 3x3 kernel – makefile8 - examples of sobel filters – makefile9 - examples of frac16 data correlation and auto-correlation function – makefile9a - examples of FIR filters – makefile9b - examples of float data IIR filters – makefile9c - examples of frac16 data IIR filters
6 Function API
6.1 Bit reversal permutation for 16-bit data
and Signal Processing, Vol. Assp-35, No. 8, August 1987. Table 1. bitrev_table_16bit arguments
6.2 Bit reversal permutation for 32-bit data
Table 2. bitrev_table_32bit arguments
and Signal Processing, Vol. Assp-35, No. 8, August 1987.
6.3 N-point radix-4 complex to complex float in-place FFT
the input data into inout_buffer. There is used radix-4 FFT algorithm. Table 3. fft_radix4_float arguments Use predefined w_table_radix4_float_N arrays.
where i is the imaginary unit with the property that: . Note: There must be at least 32 bytes of readable memory behind inout_buffer. Performance: See Section 7 and Table 32.
6.4 N-point radix-4 complex to complex frac16/frac32 in-place
Table 4. fft_radix4_frac32 arguments
inout_buffer. There is used radix-4 FFT algorithm. where i is the imaginary unit with the property that: . Note: There must be at least 32 bytes of readable memory behind inout_buffer. Performance: See Section 7 and Table 35. Use predefined w_table_radix4_frac32_N arrays. Table 4. fft_radix4_frac32 arguments (continued)
6.5 N-point quad radix-2 comple x to complex float in-place FFT
two stages are calculated in one loop (quad butterfly). where i is the imaginary unit with the property that: . Note: There must be at least 32 bytes of readable memory behind inout_buffer. Performance: See Section 7 and Table 33. Table 5. fft_quad_float arguments Use predefined w_table_radix2_float_N arrays.
6.6 N-point quad radix-2 comple x to complex frac16/frac32 in-
Table 6. fft_quad_frac32 arguments Use predefined w_table_radix2_frac32_N arrays.
where i is the imaginary unit with the property that: . Note: There must be at least 16 bytes of readable memory behind inout_buffer. Performance: See Section 7 and Table 36.
6.7 Last stage of N-point radix- 2 complex to complex float in-
Table 7. fft_radix2_last_stage_float arguments
lengths which are odd power of two (128, 512, 2048). Note: There must be at least 16 bytes of readable memory behind inout_buffer. Performance: See Section 7 and Table 34.
6.8 Last stage of N-point radix- 2 complex to complex frac32 in-
Use predefined w_table_radix2_float_N arrays. Table 7. fft_radix2_last_stage_float arguments (continued) Table 8. fft_radix2_last_stage_frac32 arguments
lengths which are odd power of two (128, 512, 2048). Note: There must be at least 16 bytes of readable memory behind inout_buffer. Performance: See Section 7 and Table 37.
6.9 Split function of N-poin t real to complex float FFT
Use predefined w_table_radix2_frac32_N arrays. Table 8. fft_radix2_last_stage_frac32 arguments (continued)
Description: Split function of N-point real to complex float in-place fast Fourier transform (FFT). function gives the first half of the output spectrum. By default the N/2 output item is not calculated. Table 9. fft_real_split_float arguments of half the length, data ordered x_Re(0) x_Im(0) x_Re(1) x_Im(1)... Use predefined wa_table_float_N arrays. Use predefined wb_table_float_N arrays.
Here is the summary how the real to complex float in-place FFT can be calculated using the split function: – on real input data in_Re(0) in_Re(1) ... in_Re(N-1), calculate complex to complex FFT of half the length – call the split function which calculates the half of the spectrum X_Re(0) X_Im(0) X_Re(1) X_Im(1) ... X_Re(N/2-1) X_Im(N/2-1) – if N2_REALPART is defined to 1, the split function saves the X_Re(N/2) into X_Im(0) Algorithm: Input data in memory: , Re - real part, Im - imaginary part Equation 9 The split function performs calculation of the output sequence from the input sequence according to the following equations: Equation 10 Equation 11 Equation 12 for each k from 1 to N/2-1 where: Equation 13 Equation 14 Equation 15 * denotes complex conjugate operation i is the imaginary unit Equation 16 output data in memory: when N2_REALPART is defined to 0 when N2_REALPART is defined to 1 2---- 1– x_Im N 2---- 1– Xk xk X N 2---- 2---- k– += wa k 1 2--- 1i W N k– = wb k 1 2--- 1i W N k+ = WN e i2 2---- 1– X_Im N 2---- 1– X_Re 0 X_Re N 2---- 2---- 1– X_Im N 2---- 1–
Performance: See Section 7 and Table 38.
6.10 Split function of N-poin t real to complex frac32 FFT
Table 10. fft_real_split_frac32 arguments
Description: Split function of N-point real to complex frac32 in-place fast Fourier transform (FFT). the input data into y. The function gives the first half of the output spectrum. By default the N/2 output item is not calculated. Use predefined wa_table_frac32_N arrays. Use predefined wb_table_frac32_N arrays. Table 10. fft_real_split_frac32 arguments (continued)
Here is the summary how the real to complex frac32 in-place FFT can be calculated using the split function: – on real input data in_Re(0) in_Re(1) ... in_Re(N-1), calculate complex to complex FFT of half the length – call the split function which calculates the half of the spectrum X_Re(0) X_Im(0) X_Re(1) X_Im(1) ... X_Re(N/2-1) X_Im(N/2-1) – if N2_REALPART is defined to 1, the split function saves the X_Re(N/2) into X_Im(0) – note that the FFT output is divided by N since scaling is by default turned on Algorithm: Input data in memory: , Re - real part, Im - imaginary part Equation 17 , divided by two only in the case when SCALING is set to 1 The split function performs calculation of the output sequence from the input sequence according to the following equations: Equation 18 Equation 19 Equation 20 for each k from 1 to N/2-1 where: Equation 21 Equation 22 Equation 23 * denotes complex conjugate operation i is the imaginary unit Equation 24 output data in memory: when N2_REALPART is defined to 0 2---- 1– x_Im N 2---- 1– Xk xk X N 2---- 2---- k– += wa k 1 2--- 1i W N k– = wb k 1 2--- 1i W N k+ = WN e i2 2---- 1– X_Im N 2---- 1–
Performance: See Section 7 and Table 40.
6.11 Complex float windowing function
Table 11. window_apply_complex_float arguments
- All vectors must be double word aligned. Al l vectors have the following memory layout:
re(0) im(0) re(1) im(1) ... re(N-1) im(N-1), where re is real part and im is imaginary part. as x vector (in-place windowing).
where x denotes complex multiplication. Note: There must be 16 bytes of readable memory behind x and w buffers. Performance: See Section 7 and Table 42.
6.12 Complex frac16 windowing function
Table 12. window_apply_complex_frac16 arguments
- All vectors must be word aligned. All ve ctors have the following memory layout:
re(0) im(0) re(1) im(1)... re(N-1) im(N-1), where re is real part and im is imaginary part. as x vector (in-place windowing).
are written into y vector. The y vector can be the same as x vector (in-place windowing). The output scaling is configurable by constant definition in the function source file: .set SCALING, 1 #/* 0 - off, 1 - on (output divided by 2) */ By default it is turned on. The scaling is performed by dividing output data by 2. Algorithm: Equation 26 for each k = 0,1,...N-1 where x denotes complex multiplication. The output value is divided by 2 when SCALING == 1. Note: There must be 8 bytes of readable memory behind x and w buffers. If SCALING == 1, then w array mustn't have any value equal to -1 (-32768) since there is used integer multiplication for fractional data. Performance: See Section 7 and Table 43. Example 12. window_apply_complex_frac16 #include "libdsp2.h" short x[2*64+4]; /* +4 to ensure there is 8 bytes of readable memory behind buffer, must be aligned to 4 bytes */ short w[2*64+4]; /* +4 to ensure there is 8 bytes of readable memory behind buffer, must be aligned to 4 bytes */ void main(void) unsigned int i, N; /* length of complex vectors is 64 */ N = 64; /* prepare example input data */ for (i = 0; i < 2*N; i++) w[i] = (i+2*N)<<5; /* windowing function on complex frac16 data, x[i] = x[i]*w[i] window_apply_complex_frac16(N, x, x, w);
6.13 Real float windowing function
Function call: void window_apply_real_float(unsigned int N, float *x, float *y, float *w); yk
readable memory behind window vector w. Performance: See Section 7 and Table 44.
6.14 Real frac16 windowing function
Table 13. window_apply_real_float arguments
- All vectors must be double word aligned. Al l vectors have the following memory layout:
into y vector. The y vector can be the same as x vector (in-place windowing). readable memory behind window vector w. Performance: See Section 7 and Table 45. Table 14. window_apply_real_frac16 arguments
- All vectors must be word aligned. All ve ctors have the following memory layout:
- Aquisition of in-cylinder pressure at any sampling position [i] (aquisition window
- Calculation of cylinder volume V[i] at any sampling position [i], V[i] can be
- Calculation of heat release rate (QIST), (supposed delta is constant e.g. 0,5), for
in both QV and QP equations.
- Calculation of mass fraction burned MFB (integration of heat release rate), initial
Table 15. mfb50_pmh arguments
- Both pressure and volume vector must be double word aligned.
Also note that the function writes calculated MFB[1] at the P_MFB array position 0. 5. Find maximum MFBmax and minimum MFBmin value from MFB[i], i = 1,2...N-2 6. Calculate MFB50 value as: Equation 31 Calculation of PMH index: 7. Starting with PMH_old = 0, calculate for each i = 1,2...N-1: Equation 32 Note: There must be 8 bytes of readable memory behind input vector P_MFB and V. Performance: See Section 7 and Table 46. Example 15. mfb50_pmh #include "libdsp2.h" float P[740]; float V[740]; float K = 1.4F; unsigned int N = 714; float PMH; unsigned int MFB50_index; float MFB50; void main(void) /* from pressure vector P and volume vector V, calculate MFB50 value, PMH index and mass fraction burned (MFB), MFB returned back in P vector, MFB1 at P array position 0 */ MFB50 = mfb50_pmh(N, P, V, K, &PMH); /* search for MFB50 value in mass fraction burned (P) vector and return index at which the MFB50 value was found */ MFB50_index = mfb50_index(N, P, MFB50); 6.16 mfb50_index - pressure sensing function 2 Function call: unsigned int mfb50_index(unsigned int N, float *MFB, float MFB50); MFB50 MFBmax MFBmin+ PMH PMH_old PMA DVA+=
MFB50 value was found. The returned index is called MFB50% position index.
- For each i = 2,3 ... N-2, calculate absolute value of difference MFB[i] and MFB50:
- Find index i at which the diff[i] has minimal value.
Note: There must be 8 bytes of readable memory behind input vector MFB. Performance: See Section 7 and Table 47. Table 16. mfb50_index arguments
- The MFB vector must be double word aligned.
Description: Computes the 2-D convolution on MxN input image using a 3x3 convolution kernel. symbol defined in function source file. Table 17. conv3x3 arguments
- a and b must be word aligned.
- c must be half word aligned and there must be 1 byte of readable memory behind c.
- Shift each computed bij by shift bits to the right: 3. Range limit to 0..255: if (bij <0 ) t h e n bij =0 , if (bij > 255) then bij =2 5 5 Note: The input/output images and convolution kernel must be properly aligned in memory as described in Table 17. And there must be 1 byte of readable memory behind the convolution kernel c. Performance: See Section 7 and Table 48. Example 17. conv3x3 #include "libdsp2.h" /* #pragma and ALIGN macros used to align to 4 bytes */ #pragma alignvar (4) #endif ALIGN_DCC(4) unsigned char a[16*12]; /* #pragma and ALIGN macros used to align to 2 bytes */ #pragma alignvar (2) #endif ALIGN_DCC(2) signed char c[3*3] ALIGN_MWERKS(2) = { -1, -2, -1, 0, 0, 0, 1, 2, 1, /* #pragma and ALIGN macros used to align to 4 bytes */ #pragma alignvar (4) #endif ALIGN_DCC(4) unsigned char b[16*12] ALIGN_MWERKS(4); unsigned short M, N, shift; void main(void) M = 16; N = 12; shift = 4; conv3x3(a, b, c, M, N, shift); bij bij 2shift=
- Compute horizontal sobel filter, i.e. compute 2-D convolution with the following kernel:
- Compute vertical sobel filter, i.e. comp ute 2-D convolution with the following kernel:
- Add absolute values of horizontal and vertical sobel filters
Performance: See Section 7 and Table 49. Table 18. sobel3x3 arguments
- a and b must be word aligned.
inner loop. The ZERO_LASTCOL is a symbol defined in function source file. Table 19. sobel3x3_horizontal arguments
- a and b must be word aligned.
Algorithm: 1. Compute horizontal sobel filter, i.e. compute 2-D convolution with the following kernel: 2. Get absolute value of result 3. Range limit to 0..255 Note: The input/output images must be properly aligned in memory as described in Table 19. Performance: See Section 7 and Table 50. Example 19. sobel3x3_horizontal #include "libdsp2.h" /* #pragma and ALIGN macros used to align to 4 bytes */ #pragma alignvar (4) #endif ALIGN_DCC(4) unsigned char a[16*12]; /* #pragma and ALIGN macros used to align to 4 bytes */ #pragma alignvar (4) #endif ALIGN_DCC(4) unsigned char b[16*12] ALIGN_MWERKS(4); unsigned short M, N, shift; void main(void) M = 16; N = 12; sobel3x3_horizontal(a, b, M, N); 6.20 sobel3x3_vertical - vertical sobel filter Function call: void sobel3x3_vertical(unsigned char *a, unsigned char *b, unsigned short M, unsigned short N); Gy 1– 2– 1– 000 120
loop. The ZERO_LASTCOL is a symbol defined in function source file.
- Compute vertical sobel filter, i.e. comput e 2-D convolution with the following kernel:
- 2. Get absolute value of result
Performance: See Section 7 and Table 51. Table 20. sobel3x3_vertical arguments
- a and b must be word aligned.
arithmetic with saturation so the output will never overflow. Note: The x and y can be the same array, in that case the auto-correlation is computed. Performance: See Section 7 and Table 52. Table 21. corr_frac16 arguments
- The x,y,r data are in fractional 16-bit format in range -1 to 1. The arrays x,r must be word aligned,
the array y must be half-word aligned (implicit alignment of short data).
output samples are written to the array y. Table 22. fir_float arguments arguments (1)
- The arrays x, y, h must be double-word aligned. There must be 8 bytes of readable memory behind
Algorithm: Equation 36 for each n from 0 to N-1 Note: The filter coefficients must be stored in reversed order. Performance: See Section 7 and Table 53. Example 22. fir_float #include "libdsp2.h" /* #pragma and ALIGN macros used to align to 8 bytes */ #pragma alignvar (8) #endif ALIGN_DCC(8) float x[288/*+2*/] ALIGN_MWERKS(8); /* +2 to ensure there are 8 bytes of readable memory behind x */ #pragma alignvar (8) #endif ALIGN_DCC(8) float y [256] ALIGN_MWERKS(8); #pragma alignvar (8) #endif ALIGN_DCC(8) float hr[33/*+2*/] ALIGN_MWERKS(8) = { /* +2 to ensure there are 8 bytes of readable memory behind hr */ -0.0015288448F,-0.0019041377F,-0.0025120102F,-0.0031517229F,- 0.0033815748F,- 0127558533F,0.0049703708F,0.0000000000F,-0.0025689987F,- 0.0033815748F,-0.0031517229F,-0.0025120102F,-0.0019041377F,- 0.0015288448F, unsigned short N, ntaps; void main(void) /* filter the samples in x with FIR filter of 32nd order, */ /* write result into y, hr are filter coefficients stored */ /* in reversed order */ N = 256; k0= ntaps 1–
x, output samples are written to the array y. There is used arithmetic with saturation. The filter coefficients must be stored in reversed order. Performance: See Section 7 and Table 54. Table 23. fir_frac16 arguments (1)
- The x,y,h data are in fractional 16-bit format in range -1 to 1. The arrays x, y must be word aligned,
readable memory behind the array h and 4 bytes of readable memory behind the array x.
Table 24. iir_float_1st arguments (1)
- The arrays x,y,s must be double-word aligned, the array c must be word aligned (implicit alignment
new values of x(-1), y(-1) in the array s to be ready for next function call.
Description: Computes the first-order IIR filter on float data. The input samples are stored in the array x, output samples are written to the array y. Algorithm: Equation 39 for each n from 0 to N-1 Performance: See Section 7 and Table 55. Example 24. iir_float_1st #include "libdsp2.h" /* #pragma and ALIGN macros used to align to 8 bytes */ #pragma alignvar (8) #endif ALIGN_DCC(8) float x[256/*+4*/] ALIGN_MWERKS(8); /* +4 to ensure there are 16 bytes of readable memory behind x */ #pragma alignvar (8) #endif ALIGN_DCC(8) float y [256] ALIGN_MWERKS(8); #pragma alignvar (8) #endif ALIGN_DCC(8) float s [2] ALIGN_MWERKS(8) = {0,0}; float c [3] = {0.5157131330F,0.5157131330F,0.0314262660F}; unsigned short N; void main(void) /* filter the samples in x with first-order IIR filter, */ /* write result into y */ N = 256; iir_float_1st(N, x, y, c, s); 6.25 iir_float_2nd - float second-order IIR filter Function call: void iir_float_2nd (unsigned short N, float *x, float *y, float *c, float *s);
the array x, output samples are written to the array y. Performance: See Section 7 and Table 56. Table 25. iir_float_2nd arguments
- The arrays x,y,s must be double-word aligned, the array c must be word aligned (implicit alignment
new values of x(-2), x(-1), y(-2), y(-1) in the array s to be ready for next function call.
the iir_float_2nd function for each second-order IIR filter in the cascade. Table 26. iir_float_casc arguments (1)
- The arrays x,y,s must be double-word aligned, the array c must be word aligned (implicit alignment
returned new values of x(-2), x(-1), y(-2), y(-1) in the array s to be ready for next function call.
for each n = 0,1...N-1 The i-order filter is implemented using the cascade of m IIR filters of second-order: Equation 42 Equation 43 Equation 44 for each n = 0,1...N-1 Performance: See Section 7 and Table 57. Example 26. iir_float_casc #include "libdsp2.h" /* #pragma and ALIGN macros used to align to 8 bytes */ #pragma alignvar (8) #endif ALIGN_DCC(8) float x[256/*+4*/] ALIGN_MWERKS(8); /* +4 to ensure there are 16 bytes of readable memory behind x */ #pragma alignvar (8) #endif ALIGN_DCC(8) float y [256/*+4*/] ALIGN_MWERKS(8); /* +4 to ensure there are 16 bytes of readable memory behind y */ #pragma alignvar (8) #endif ALIGN_DCC(8) float s[3*4] ALIGN_MWERKS(8) = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; float c[3*5] = {0.3284466238F, 0.6596805377F, 0.3312418003F, 0.0639408215F, 0.0183196767F, 0.2531886900F, 0.5063763109F, 0.2531936959F, 0.0736238464F, 0.1725312505F, 0.4280607669F, 0.8524906977F, 0.4244401939F, 0.0998014847F, 0.5894355624F,};
saturation so the output will never overflow. Performance: See Section 7 and Table 58. Table 27. iir_frac16_1st arguments
- The x,y,c,s data are in fractional 16-bit format in range -1 to 1. The arrays x,y,s must be word
array s to be ready for next function call.
saturation so the output will never overflow. Table 28. iir_frac16_2nd arguments
- The x,y,c,s data are in fractional 16-bit format in range -1 to 1. The arrays x,y,s must be word
y(-1) in the array s to be ready for next function call.
Algorithm: Equation 46 for each n from 0 to N-1 Performance: See Section 7 and Table 59. Example 28. iir_frac16_2nd #include "libdsp2.h" /* #pragma and ALIGN macros used to align to 4 bytes */ #pragma alignvar (4) #endif ALIGN_DCC(4) short x[256/*+2*/] ALIGN_MWERKS(4); /* +2 to ensure there are 4 bytes of readable memory behind x */ #pragma alignvar (4) #endif ALIGN_DCC(4) short y[256] ALIGN_MWERKS(4); #pragma alignvar (4) #endif ALIGN_DCC(4) short s[4] ALIGN_MWERKS(4) = {0,0,0,0}; short c[5] = {10209,20417,10209,2413,5654}; unsigned short N; void main(void) /* filter the samples in x with second-order IIR filter, */ /* write result into y */ N = 256; iir_frac16_2nd(N, x, y, c, s); 6.29 iir_frac16_casc - cascade of frac16 second-order IIR filters Function call: #define iir_frac16_casc iir_frac16_casc_c void iir_frac16_casc_c(unsigned short N, short *x, short *y, short *c, short *s, unsigned short m);
used the arithmetic with saturation so the output will never overflow. Performance: See Section 7 and Table 60. Table 29. iir_frac16_casc arguments (1)
- The x,y,c,s data are in fractional 16-bit format in range -1 to 1. The arrays x,y,s must be word
y(-2), y(-1) in the array s to be ready for next function call.
Example 29. iir_frac16_casc #include "libdsp2.h" /* #pragma and ALIGN macros used to align to 4 bytes */ #pragma alignvar (4) #endif ALIGN_DCC(4) short x[256/*+2*/] ALIGN_MWERKS(4); /* +2 to ensure there are 4 bytes of readable memory behind x */ #pragma alignvar (4) #endif ALIGN_DCC(4) short y[256/*+2*/] ALIGN_MWERKS(4); /* +2 to ensure there are 4 bytes of readable memory behind y */ #pragma alignvar (4) #endif ALIGN_DCC(4) short s[3*4] ALIGN_MWERKS(4) = {0,0,0,0,0,0,0,0,0,0,0,0}; short c[3*5] = {10763,21616,10854,2095,600, 8296,16593,8297,2413,5654, 14027,27934,13908,3270,19315,}; unsigned short N; void main(void) /* filter the samples in x with sixth-order IIR filter, */ /* write result into y */ N = 256; iir_frac16_casc(N, x, y, c, s, 3); 6.30 iir_frac16_2nd_hc - frac16 second-order IIR filter with half coefficients Function call: void iir_frac16_2nd_hc(unsigned short N, short *x, short *y, short *c, short *s); Arguments: dkkdkdkd Returns:
Performance: See Section 7 and Table 61. Table 30. iir_frac16_2nd_hc arguments
- The x,y,c,s data are in fractional 16-bit format in range -1 to 1. The arrays x,y,s must be word
y(-1) in the array s to be ready for next function call.
#pragma alignvar (4) #endif ALIGN_DCC(4) short s[4] ALIGN_MWERKS(4) = {9830,13107,-3932,11665}; short c[5] = {10209,20417,10209,2413,5654}; unsigned short N; void main(void) /* filter the samples in x with second-order IIR filter, */ /* write result into y, coefficients in c are stored */ /* divided by 2 */ N = 256; iir_frac16_2nd_hc(N, x, y, c, s);
7 Performance
- Code Memory (Internal Flash) - cache on
- Data Memory (Internal RAM) - cache on
- Stack Memory - locked in cache
- Data acquired on the MPC5554 with SIU_MIDR = 0x55540011
- Branch Target Buffer (BTB) enabled
- BIUCR = 0x00094BFD The “Improvement to C function” column shows performance increase comparing the assembly code to a respective C function, the value is calculated as a ratio of the number_of_clock_cycles_of_C_ function/number_of_clock_cycles_of_optimized_ library_ function. The number of clock cycles are taken for the third function call. The C-code was compiled in CodeWarrior for PowerPC V1.5 beta2, Global Optimizations set to level 4, Optimize for Faster Execution Speed, Instruction Scheduling and Peephole Optimization turned on. The IPC column shows instructions per cycle.
Table 31. Code size
- N2_REALPART configured to 0, for N2_REALPART configured to 1 code size is 460 bytes.
- The code size is the same for N2_REALPART configured to 0 or 1.
- Valid for both scaling on and off.
- ZERO_LASTCOL configured to 0, if configured to 1 t he size is 4 bytes greater for conv3x3 function and 8
bytes greater for the sobel functions.
- The iir_float_casc (iir_frac16_casc) function calls function iir_float_2nd (iir_frac16_2nd). The code size in
Peephole Optimization turned on. Table 31. Code size (continued) Table 32. Radix-4 complex to complex float in-place FFT (1)
- The clock cycles include bit reversing by bitrev_table_32bit and FFT computation by fft_radix4_float function. w_table in
internal flash, seed_table in internal flash.
Table 33. Quad radix-2 complex to complex float in-place FFT (1)
- The clock cycles include bit reversing by bitrev_table_32bit and FFT computation by fft_quad_float function. w_table in
internal flash, seed_table in internal flash. Table 34. Radix-2 complex to complex float in-place FFT (1)
- The clock cycles include bit reversin g by bitrev_table_32bit and FFT computation by fft_quad_float function and
fft_radix2_last_stage_float function. w_table in internal flash, seed_table in internal flash. Table 35. Radix-4 complex to complex frac16/frac32 in-place FFT, scaling on (1)
- The clock cycles include bit reversing by bitrev_table_16bit and FFT computation by fft_radix4_frac32 function. w_table in
internal flash, seed_table in internal flash. Table 36. Quad radix-2 complex to complex frac16/frac32 in-place FFT, scaling on (1)
the same as for respective float FFT plus N/8.
- The clock cycles include bit reversing by bitrev_table_16bit and FFT computation by fft_quad_frac32 function. w_table in
internal flash, seed_table in internal flash. Table 37. Radix-2 complex to complex frac32 in-place FFT, scaling on (1)
- The clock cycles include bit reversin g by bitrev_table_16bit and FFT computation by fft_quad_frac32 function and
fft_radix2_last_stage_frac32 function. w_table in internal flash, seed_table in internal flash. Table 38. Real to complex float in-place FFT (N odd power of two) (1)
- The clock cycles include bit reversing by bitrev_table_32bit and FFT computation by fft_radix4_float function and
fft_real_split_float function. w_table in internal flash, seed_table in internal flash, wa_table and wb_table in internal flash. Table 39. Real to complex float in-place FFT (N even power of two) (1)
- The clock cycles include bit reversin g by bitrev_table_32bit and FFT computation by fft_quad_float function,
wa_table and wb_table in internal flash. N2_REALPART set to 0.
place FFTs without scaling is the same as for respective float FFT plus N/16. Table 40. Real to complex frac16/frac32 in-place FFT, scaling on (N odd power of two) (1)
- The clock cycles include bit reversing by bitrev_table_16bit and FFT computation by fft_radix4_frac32 function and
fft_real_split_frac32 function. w_table in internal flash, seed_table in internal flash, wa_table and wb_table in internal flash. Table 41. Real to complex frac16/frac32 in-place FFT, scaling on (N even power of two) (1)
- The clock cycles include bit reversin g by bitrev_table_16bit and FFT computation by fft_quad_frac32 function,
flash, wa_table and wb_table in internal flash. N2_REALPART set to 0. Table 42. Complex float windowing function (1)
- w vector in internal flash.
Table 43. Complex frac16 windowing function (1)
- w vector in internal flash. The t able is valid for both scaling on and off.
Table 44. Real float windowing function (1)
- w vector in internal flash.
Table 45. Real frac16 windowing function (1)
- w vector in internal flash.
number of instructions in the loop). number of instructions in the loop). Note: The number of instructions executed is 76+(M-2)*(39+53*(N-4)/4). Table 46. mfb50_pmh - pressure sensing function 1
- N is length of P_MFB and V vectors.
Table 47. mfb50_index - pressure sensing function 2
- N is length of MFB vector.
Table 48. conv3x3 - 2-D convolution with 3x3 kernel (1)
- All measurements executed wi th convolution kernel c placed in internal RAM.
- MxN is size of input and output matrix (M is number of rows).
Table 49. sobel3x3 - sobel filter (1)
- The number of instructions exec uted is 38+(M-2)*(37+48*(N-4)/4).
- MxN is size of input and output matrix (M is number of rows).
Table 50. sobel3x3_horizontal - horizontal sobel filter (1)
- The number of instructions exec uted is 28+(M-2)*(26+33*(N-4)/4).
- MxN is size of input and output matrix (M is number of rows).
Table 51. sobel3x3_vertical - vertical sobel filter (1)
- The number of instructions exec uted is 28+(M-2)*(27+33*(N-4)/4).
- MxN is size of input and output matrix (M is number of rows).
Table 52. corr_frac16 - correlation function
- N - length of input vectors, M - length of output vector.
Table 53. fir_float - FIR filter for float data
- N - number of output samples, ntaps - number of filter coefficients.
Table 54. fir_frac16 - FIR filter for frac16 data
- N - number of output samples, ntaps - number of filter coefficients.
Table 55. iir_float_1st - first-order IIR filter for float data
- N - number of input/output samples.
Table 56. iir_float_2nd - second-order IIR filter for float data
- N - number of input/output samples.
Table 57. iir_float_casc - cascade of second-order IIR filters for float data
- N - number of input/output samples, m - number of second-order filters.
Table 58. iir_frac16_1st - first-order IIR filter for frac16 data
- N - number of input/output samples.
Table 59. iir_frac16_2nd - second-order IIR filter for frac16 data
- N - number of input/output samples.
Table 60. iir_frac16_casc - cascade of second-order IIR filters for frac16 data
- N - number of input/output samples, m - number of second-order filters.
Table 61. iir_frac16_2nd_hc - second-order IIR filter for frac16 data with half coefficients
- N - number of input/output samples.
8 Revision history
Table 62. Document revision history 18-Sep-2013 2 Updated Disclaimer.