1 2 /* ---------------------------------------------------------------------- 3 * Project: CMSIS DSP Library 4 * Title: arm_dtw_path_f32.c 5 * Description: Warping path 6 * 7 * $Date: 23 April 2021 8 * $Revision: V1.9.0 9 * 10 * Target Processor: Cortex-M and Cortex-A cores 11 * -------------------------------------------------------------------- */ 12 /* 13 * Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved. 14 * 15 * SPDX-License-Identifier: Apache-2.0 16 * 17 * Licensed under the Apache License, Version 2.0 (the License); you may 18 * not use this file except in compliance with the License. 19 * You may obtain a copy of the License at 20 * 21 * www.apache.org/licenses/LICENSE-2.0 22 * 23 * Unless required by applicable law or agreed to in writing, software 24 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 * See the License for the specific language governing permissions and 27 * limitations under the License. 28 */ 29 30 #include "dsp/distance_functions.h" 31 #include <limits.h> 32 #include <math.h> 33 #include <stdlib.h> 34 35 36 /** 37 @addtogroup DTW 38 @{ 39 */ 40 41 42 /** 43 * @brief Window for dynamic time warping computation 44 * @param[in] windowType Type of window 45 * @param[in] windowSize Window size 46 * @param[in,out] pWindow Window 47 * @return Error if window type not recognized 48 * 49 * @par Windowing matrix 50 * The window matrix will contain 1 for the 51 * position which are accepted and 0 for the 52 * positions which are rejected. 53 * 54 * The input matrix must already contain a buffer 55 * and the number of rows (query length) and columns 56 * (template length) must be initialized. 57 * The function will fill the matrix with 0 and 1. 58 * 59 */ arm_dtw_init_window_q7(const arm_dtw_window windowType,const int32_t windowSize,arm_matrix_instance_q7 * pWindow)60arm_status arm_dtw_init_window_q7(const arm_dtw_window windowType, 61 const int32_t windowSize, 62 arm_matrix_instance_q7 *pWindow) 63 { 64 const int32_t queryLength = pWindow -> numRows; 65 const int32_t templateLength = pWindow -> numCols; 66 67 switch(windowType) 68 { 69 case ARM_DTW_SAKOE_CHIBA_WINDOW: 70 { 71 for(int32_t q = 0; q < queryLength; q++) 72 { 73 for(int32_t t = 0; t < templateLength; t++) 74 { 75 pWindow->pData[templateLength*q + t] = (q7_t)(abs(q-t) <= windowSize); 76 } 77 } 78 } 79 break; 80 /* 81 case ARM_DTW_ITAKURA_WINDOW: 82 { 83 for(int32_t q = 0; q < queryLength; q++) 84 { 85 for(int32_t t = 0; t < templateLength; t++) 86 { 87 pWindow->pData[templateLength*q + t] = (q7_t)( 88 (t < 2 * q) && 89 (q <= 2 * t) && 90 (q >= queryLength - 1 - 2 * (templateLength - t)) && 91 (t > templateLength - 1 - 2 * (queryLength - q))); 92 } 93 } 94 } 95 break; 96 */ 97 case ARM_DTW_SLANTED_BAND_WINDOW: 98 { 99 for(int32_t q = 0; q < queryLength; q++) 100 { 101 for(int32_t t = 0; t < templateLength; t++) 102 { 103 float32_t diag = (1.0f * q * templateLength / queryLength); 104 pWindow->pData[templateLength*q + t] = (q7_t)(fabsf((float32_t)t - diag) <= (float32_t)windowSize); 105 } 106 } 107 } 108 break; 109 110 default: 111 return(ARM_MATH_ARGUMENT_ERROR); 112 } 113 114 return(ARM_MATH_SUCCESS); 115 } 116 117 /** 118 * @} end of DTW group 119 */ 120 121