Project Ne10
An open, optimized software library for the ARM architecture.
NE10_sample_real_fft.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011-16 ARM Limited and Contributors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ARM Limited nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #include "NE10.h"
31 
32 #define SAMPLES 16
33 
39 {
40  ne10_float32_t src[SAMPLES] = {}; // A source array of input data
41  ne10_fft_cpx_float32_t dst[(SAMPLES / 2) + 1] = {}; // A destination array for the transformed data
42  ne10_fft_r2c_cfg_float32_t cfg; // An FFT "configuration structure"
43 
44  // Initialise Ne10, using hardware auto-detection to set library function pointers
45  if (ne10_init() != NE10_OK)
46  {
47  fprintf(stderr, "Failed to initialise Ne10.\n");
48  return 1;
49  }
50 
51  // Prepare the real-to-complex single precision floating point FFT configuration
52  // structure for inputs of length `SAMPLES`. (You need only generate this once for a
53  // particular input size.)
55 
56  // Generate test input values
57  for (int i = 0; i < SAMPLES; i++)
58  {
59  src[i] = (ne10_float32_t)rand() / RAND_MAX * 50.0f;
60  }
61 
62  // Perform the FFT
63  ne10_fft_r2c_1d_float32(dst, src, cfg);
64 
65  // Display the results
66  for (int i = 0; i < SAMPLES; i++)
67  {
68  printf( "IN[%2d]: %10.4f\t", i, src[i]);
69  if (i <= SAMPLES / 2)
70  printf("OUT[%2d]: %10.4f + %10.4fi", i, dst[i].r, dst[i].i);
71  printf("\n");
72  }
73 
74  // Free the allocated configuration structure
76 
77  return 0;
78 }
ne10_fft_r2c_cfg_float32_t ne10_fft_alloc_r2c_float32(ne10_int32_t nfft)
Creates a configuration structure for variants of ne10_fft_r2c_1d_float32 and ne10_fft_c2r_1d_float32...
float ne10_float32_t
Definition: NE10_types.h:80
void(* ne10_fft_r2c_1d_float32)(ne10_fft_cpx_float32_t *fout, ne10_float32_t *fin, ne10_fft_r2c_cfg_float32_t cfg)
Mixed radix-2/4 real-to-complex FFT of single precision floating point data.
void ne10_fft_destroy_r2c_float32(ne10_fft_r2c_cfg_float32_t)
Destroys the configuration structure allocated by ne10_fft_alloc_r2c_float32 (frees memory...
Definition: NE10_fft.c:593
#define SAMPLES
int real_fft_sample_main(void)
ne10_result_t ne10_init(void)
Definition: NE10_init.c:44
#define NE10_OK
Definition: NE10_types.h:65