Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "stm32f4xx.h"
  4. #define ARM_MATH_CM4
  5. #include "arm_math.h"
  6.  
  7.  
  8. uint32_t random32bit=0;
  9. float avg_temp = 0;
  10. uint32_t prev = 0;
  11.  
  12. volatile uint32_t msTicks = 0; /* counts 1ms timeTicks */
  13.  
  14. // SysTick Handler (Interrupt Service Routine for the System Tick interrupt)
  15. void SysTick_Handler(void){
  16. msTicks++;
  17. }
  18.  
  19. // initialize the system tick
  20. void InitSystick(void){
  21. SystemCoreClockUpdate(); /* Get Core Clock Frequency */
  22. if (SysTick_Config(SystemCoreClock / 1000)) { /* SysTick 1 msec interrupts */
  23. while (1); /* Capture error */
  24. }
  25. }
  26.  
  27. void linear_least_squares(float32_t * Y_f32, float32_t * X_f32,
  28. float32_t * W_f32, uint32_t n, uint32_t m, uint32_t p)
  29. {
  30. float32_t XT_f32[16];
  31. float32_t XMXT_f32[4];
  32. float32_t XMXTI_f32[4];
  33. float32_t YMXT_f32[2];
  34. //float32_t W_f32[2];
  35.  
  36. arm_matrix_instance_f32 X;
  37. arm_matrix_instance_f32 XT;
  38. arm_matrix_instance_f32 XMXT;
  39. arm_matrix_instance_f32 XMXTI;
  40. arm_matrix_instance_f32 Y;
  41. arm_matrix_instance_f32 YMXT;
  42. arm_matrix_instance_f32 W;
  43.  
  44. arm_mat_init_f32(&X,m,n,X_f32);
  45. arm_mat_init_f32(&XT,n,m,XT_f32);
  46. arm_mat_init_f32(&XMXT,m,m,XMXT_f32);
  47. arm_mat_init_f32(&XMXTI,m,m,XMXTI_f32);
  48. arm_mat_init_f32(&YMXT,p,m,YMXT_f32);
  49. arm_mat_init_f32(&W,p,m,W_f32);
  50.  
  51. arm_mat_trans_f32(&X,&XT);
  52. arm_mat_mult_f32(&X,&XT,&XMXT);
  53. arm_mat_inverse_f32(&XMXT,&XMXTI);
  54.  
  55.  
  56. arm_mat_init_f32(&Y,p,n,Y_f32);
  57. arm_mat_mult_f32(&Y,&XT,&YMXT);
  58. arm_mat_mult_f32(&YMXT,&XMXTI,&W);
  59.  
  60.  
  61. }
  62.  
  63. int32_t main(void){
  64.  
  65. float32_t W[2];
  66.  
  67. float32_t X[16] = {
  68. 0.8351, 0.0594, 0.3187, 0.8979, 0.2461, 0.5484, 0.7548, 0.2654,
  69. 0.4823, 0.4603, 0.9102, 0.6512,0.2340, 0.3928, 0.3926, 0.3469};
  70.  
  71. float32_t Y[8] = {
  72. 1.7207, 0.2564, 1.0798, 2.0602, 0.2290, 0.7769, 1.3231,0.3144};
  73.  
  74. int m = 2;
  75. int n = 8;
  76. int p = 1;
  77.  
  78. linear_least_squares(Y,X,W,8,2,1);
  79.  
  80. printf("%f\n ",W[0]);
  81. printf("%f\n ",W[1]);
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement