arm matrix example f32 8c source


CMSIS DSP Software Library: arm_matrix_example_f32.c Source File Main Page Modules Data Structures Files Examples File List Globals arm_matrix_example_f32.c Go to the documentation of this file.00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 29. November 2010 00005 * $Revision: V1.0.3 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_matrix_example_f32.c 00009 * 00010 * Description: Example code demonstrating least square fit to data 00011 * using matrix functions 00012 * 00013 * Target Processor: Cortex-M4/Cortex-M3 00014 * 00015 * 00016 * Version 1.0.3 2010/11/29 00017 * Re-organized the CMSIS folders and updated documentation. 00018 * 00019 * Version 1.0.1 2010/10/05 KK 00020 * Production release and review comments incorporated. 00021 * 00022 * Version 1.0.0 2010/09/20 KK 00023 * Production release and review comments incorporated. 00024 * ------------------------------------------------------------------- */ 00025 00077 #include "arm_math.h" 00078 #include "math_helper.h" 00079 00080 #define SNR_THRESHOLD 90 00081 00082 /* -------------------------------------------------------------------------------- 00083 * Test input data(Cycles) taken from FIR Q15 module for differant cases of blockSize 00084 * and tapSize 00085 * --------------------------------------------------------------------------------- */ 00086 00087 const float32_t B_f32[4] = 00088 { 00089 782.0, 7577.0, 470.0, 4505.0 00090 }; 00091 00092 /* -------------------------------------------------------------------------------- 00093 * Formula to fit is C1 + C2 * numTaps + C3 * blockSize + C4 * numTaps * blockSize 00094 * -------------------------------------------------------------------------------- */ 00095 00096 const float32_t A_f32[16] = 00097 { 00098 /* Const, numTaps, blockSize, numTaps*blockSize */ 00099 1.0, 32.0, 4.0, 128.0, 00100 1.0, 32.0, 64.0, 2048.0, 00101 1.0, 16.0, 4.0, 64.0, 00102 1.0, 16.0, 64.0, 1024.0, 00103 }; 00104 00105 00106 /* ---------------------------------------------------------------------- 00107 * Temporary buffers for storing intermediate values 00108 * ------------------------------------------------------------------- */ 00109 /* Transpose of A Buffer */ 00110 float32_t AT_f32[16]; 00111 /* (Transpose of A * A) Buffer */ 00112 float32_t ATMA_f32[16]; 00113 /* Inverse(Transpose of A * A) Buffer */ 00114 float32_t ATMAI_f32[16]; 00115 /* Test Output Buffer */ 00116 float32_t X_f32[4]; 00117 00118 /* ---------------------------------------------------------------------- 00119 * Reference ouput buffer C1, C2, C3 and C4 taken from MATLAB 00120 * ------------------------------------------------------------------- */ 00121 const float32_t xRef_f32[4] = {73.0, 8.0, 21.25, 2.875}; 00122 00123 float32_t snr; 00124 00125 00126 /* ---------------------------------------------------------------------- 00127 * Max magnitude FFT Bin test 00128 * ------------------------------------------------------------------- */ 00129 00130 int32_t main(void) 00131 { 00132 00133 arm_matrix_instance_f32 A; /* Matrix A Instance */ 00134 arm_matrix_instance_f32 AT; /* Matrix AT(A transpose) instance */ 00135 arm_matrix_instance_f32 ATMA; /* Matrix ATMA( AT multiply with A) instance */ 00136 arm_matrix_instance_f32 ATMAI; /* Matrix ATMAI(Inverse of ATMA) instance */ 00137 arm_matrix_instance_f32 B; /* Matrix B instance */ 00138 arm_matrix_instance_f32 X; /* Matrix X(Unknown Matrix) instance */ 00139 00140 uint32_t srcRows, srcColumns; /* Temporary variables */ 00141 arm_status status; 00142 00143 /* Initialise A Matrix Instance with numRows, numCols and data array(A_f32) */ 00144 srcRows = 4; 00145 srcColumns = 4; 00146 arm_mat_init_f32(&A, srcRows, srcColumns, (float32_t *)A_f32); 00147 00148 /* Initialise Matrix Instance AT with numRows, numCols and data array(AT_f32) */ 00149 srcRows = 4; 00150 srcColumns = 4; 00151 arm_mat_init_f32(&AT, srcRows, srcColumns, AT_f32); 00152 00153 /* calculation of A transpose */ 00154 status = arm_mat_trans_f32(&A, &AT); 00155 00156 00157 /* Initialise ATMA Matrix Instance with numRows, numCols and data array(ATMA_f32) */ 00158 srcRows = 4; 00159 srcColumns = 4; 00160 arm_mat_init_f32(&ATMA, srcRows, srcColumns, ATMA_f32); 00161 00162 /* calculation of AT Multiply with A */ 00163 status = arm_mat_mult_f32(&AT, &A, &ATMA); 00164 00165 /* Initialise ATMAI Matrix Instance with numRows, numCols and data array(ATMAI_f32) */ 00166 srcRows = 4; 00167 srcColumns = 4; 00168 arm_mat_init_f32(&ATMAI, srcRows, srcColumns, ATMAI_f32); 00169 00170 /* calculation of Inverse((Transpose(A) * A) */ 00171 status = arm_mat_inverse_f32(&ATMA, &ATMAI); 00172 00173 /* calculation of (Inverse((Transpose(A) * A)) * Transpose(A)) */ 00174 status = arm_mat_mult_f32(&ATMAI, &AT, &ATMA); 00175 00176 /* Initialise B Matrix Instance with numRows, numCols and data array(B_f32) */ 00177 srcRows = 4; 00178 srcColumns = 1; 00179 arm_mat_init_f32(&B, srcRows, srcColumns, (float32_t *)B_f32); 00180 00181 /* Initialise X Matrix Instance with numRows, numCols and data array(X_f32) */ 00182 srcRows = 4; 00183 srcColumns = 1; 00184 arm_mat_init_f32(&X, srcRows, srcColumns, X_f32); 00185 00186 /* calculation ((Inverse((Transpose(A) * A)) * Transpose(A)) * B) */ 00187 status = arm_mat_mult_f32(&ATMA, &B, &X); 00188 00189 /* Comparison of reference with test output */ 00190 snr = arm_snr_f32((float32_t *)xRef_f32, X_f32, 4); 00191 00192 /*------------------------------------------------------------------------------ 00193 * Initialise status depending on SNR calculations 00194 *------------------------------------------------------------------------------*/ 00195 if( snr > SNR_THRESHOLD) 00196 { 00197 status = ARM_MATH_SUCCESS; 00198 } 00199 else 00200 { 00201 status = ARM_MATH_TEST_FAILURE; 00202 } 00203 00204 00205 /* ---------------------------------------------------------------------- 00206 ** Loop here if the signals fail the PASS check. 00207 ** This denotes a test failure 00208 ** ------------------------------------------------------------------- */ 00209 if( status != ARM_MATH_SUCCESS) 00210 { 00211 while(1); 00212 } 00213 } 00214  All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines Generated on Mon Nov 29 2010 17:19:57 for CMSIS DSP Software Library by  1.7.2

Wyszukiwarka

Podobne podstrony:
arm matrix example ?2?
arm dotproduct example ?2? source
arm fir example ?2? source
arm convolution example ?2? source
arm variance example ?2? source
arm linear interp example ?2? source
arm signal converge example ?2? source
arm class marks example ?2? source
arm sin cos example ?2? source
arm sin cos example ?2? source
arm ?t bin example ?2? source
arm cmplx mag ?2? source
arm fir interpolate ?2? source
arm mat trans ?2? source
arm variance example ?2?
arm fir lattice ?2? source
arm mat ?d ?2? source
arm mat sub ?2? source
arm iir lattice ?2? source

więcej podobnych podstron