Project

General

Profile

arm_sin_cos_example_f32.c

trott, 07/04/2013 03:32 AM

 
1
/* ---------------------------------------------------------------------- 
2
* Copyright (C) 2010 ARM Limited. All rights reserved.   
3
*  
4
* $Date:        29. November 2010  
5
* $Revision:         V1.0.3
6
*  
7
* Project:             CMSIS DSP Library  
8
* Title:            arm_sin_cos_example_f32.c                  
9
*  
10
* Description:        Example code demonstrating sin and cos calculation of input signal. 
11
* 
12
* Target Processor: Cortex-M4/Cortex-M3  
13
*
14
*
15
* Version 1.0.3 2010/11/29 
16
*    Re-organized the CMSIS folders and updated documentation. 
17
* 
18
* Version 1.0.1 2010/10/05 KK 
19
*    Production release and review comments incorporated.  
20
*
21
* Version 1.0.0 2010/09/20 KK
22
*    Production release and review comments incorporated.
23
* ------------------------------------------------------------------- */ 
24
 
25
/** 
26
 * @ingroup groupExamples 
27
 */ 
28
 
29
/**    
30
 * @defgroup SinCosExample SineCosine Example    
31
 * 
32
 * \par Description:
33
 * \par
34
 * Demonstrates the Pythagorean trignometric identity with the use of Cosine, Sine, Vector
35
 * Multiplication, and Vector Addition functions.
36
 *
37
 * \par Algorithm:
38
 * \par
39
 * Mathematically, the Pythagorean trignometric identity is defined by the following equation:
40
 *  <pre>sin(x) * sin(x) + cos(x) * cos(x) = 1</pre> 
41
 * where \c x is the angle in radians. 
42
 *
43
 * \par Block Diagram:
44
 * \par
45
 * \image html sinCos.gif 
46
 * 
47
 * \par Variables Description:
48
 * \par
49
 * \li \c testInput_f32 array of input angle in radians
50
 * \li \c testOutput stores sum of the squares of sine and cosine values of input angle
51
 *
52
 * \par CMSIS DSP Software Library Functions Used:
53
 * \par
54
 * - arm_cos_f32()
55
 * - arm_sin_f32()
56
 * - arm_mult_f32()
57
 * - arm_add_f32()
58
 * 
59
 * <b> Refer  </b> 
60
 * \link arm_sin_cos_example_f32.c \endlink
61
 * 
62
 */ 
63
 
64
 
65
/** \example arm_sin_cos_example_f32.c 
66
  */  
67
 
68
#include <math.h>     
69
#include "arm_math.h" 
70
 
71
/* ---------------------------------------------------------------------- 
72
* Defines each of the tests performed 
73
* ------------------------------------------------------------------- */ 
74
#define MAX_BLOCKSIZE        32 
75
#define DELTA           (0.000001f) 
76
 
77
 
78
/* ---------------------------------------------------------------------- 
79
* Test input data for Floating point sin_cos example for 32-blockSize 
80
* Generated by the MATLAB randn() function 
81
* ------------------------------------------------------------------- */ 
82
 
83
const float32_t testInput_f32[MAX_BLOCKSIZE] =  
84
{    
85
        -1.244916875853235400,        -4.793533929171324800,        0.360705030233248850,        0.827929644170887320,        -3.299532218312426900,        3.427441903227623800,        3.422401784294607700,        -0.108308165334010680,         
86
        0.941943896490312180,        0.502609575000365850,        -0.537345278736373500,        2.088817392965764500,        -1.693168684143455700,        6.283185307179590700,        -0.392545884746175080,        0.327893095115825040,         
87
        3.070147440456292300,        0.170611405884662230,        -0.275275082396073010,        -2.395492805446796300,        0.847311163536506600,        -3.845517018083148800,        2.055818378415868300,        4.672594161978930800,         
88
        -1.990923030266425800,        2.469305197656249500,        3.609002606064021000,        -4.586736582331667500,        -4.147080139136136300,        1.643756718868359500,        -1.150866392366494800,        1.985805026477433800 
89
 
90
 
91
};  
92
 
93
const float32_t testRefOutput_f32 = 1.000000000; 
94
 
95
/* ---------------------------------------------------------------------- 
96
* Declare Global variables  
97
* ------------------------------------------------------------------- */ 
98
uint32_t blockSize = 32; 
99
float32_t  testOutput;  
100
float32_t  cosOutput;  
101
float32_t  sinOutput;  
102
float32_t  cosSquareOutput;  
103
float32_t  sinSquareOutput; 
104
 
105
/* ---------------------------------------------------------------------- 
106
* Max magnitude FFT Bin test 
107
* ------------------------------------------------------------------- */ 
108

    
109
arm_status status; 
110
 
111
int32_t main(void) 
112
{ 
113
        float32_t diff; 
114
        uint32_t i; 
115
 
116
        for(i=0; i< blockSize; i++) 
117
    { 
118
        cosOutput = arm_cos_f32(testInput_f32[i]); 
119
                sinOutput = arm_sin_f32(testInput_f32[i]); 
120
 
121
                arm_mult_f32(&cosOutput, &cosOutput, &cosSquareOutput, 1); 
122
                arm_mult_f32(&sinOutput, &sinOutput, &sinSquareOutput, 1); 
123
 
124
                arm_add_f32(&cosSquareOutput, &sinSquareOutput, &testOutput, 1);
125
 
126
                /* absolute value of difference between ref and test */ 
127
            diff = fabsf(testRefOutput_f32 - testOutput); 
128
         
129
            /* Comparison of sin_cos value with reference */ 
130
            if(diff > DELTA) 
131
            { 
132
                   status = ARM_MATH_TEST_FAILURE; 
133
            } 
134
                 
135
            if( status == ARM_MATH_TEST_FAILURE) 
136
            { 
137
               while(1); 
138
            } 
139
 
140
    } 
141

    
142
    while(1);                             /* main function does not return */
143
} 
144
 
145
 /** \endlink */ 
146