ToComplex.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: ToComplex.h
  4. * Description: Node to convert real to complex
  5. *
  6. *
  7. * Target Processor: Cortex-M and Cortex-A cores
  8. * --------------------------------------------------------------------
  9. *
  10. * Copyright (C) 2021-2023 ARM Limited or its affiliates. All rights reserved.
  11. *
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the License); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #ifndef _TOCOMPLEX_H_
  27. #define _TOCOMPLEX_H_
  28. /*
  29. Convert a stream of reals a b c d ...
  30. to complexes a 0 b 0 c 0 d 0 ...
  31. */
  32. template<typename IN, int inputSize,typename OUT,int outputSize>
  33. class ToComplex;
  34. template<typename IN, int inputSize,int outputSize>
  35. class ToComplex<IN,inputSize,IN,outputSize>: public GenericNode<IN,inputSize,IN,outputSize>
  36. {
  37. public:
  38. ToComplex(FIFOBase<IN> &src,FIFOBase<IN> &dst):GenericNode<IN,inputSize,IN,outputSize>(src,dst){
  39. };
  40. int prepareForRunning() final
  41. {
  42. if (this->willOverflow() ||
  43. this->willUnderflow()
  44. )
  45. {
  46. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  47. }
  48. return(0);
  49. };
  50. int run() final
  51. {
  52. IN *a=this->getReadBuffer();
  53. IN *b=this->getWriteBuffer();
  54. for(int i=0;i<inputSize;i++)
  55. {
  56. b[2*i]=a[i];
  57. b[2*i+1]=0;
  58. }
  59. return(0);
  60. };
  61. };
  62. #endif