GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
fft_shift.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2019 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_FFT_FFT_SHIFT_H
12#define INCLUDED_FFT_FFT_SHIFT_H
13
14#include <algorithm>
15#include <cassert>
16#include <vector>
17
18namespace gr {
19namespace fft {
20
21/*! \brief reorder FFT results which are ordered from 0 to 1 in normalized frequency
22 * to -0.5 to 0.5 by cyclic shift
23 */
24template <typename T>
26{
27public:
28 fft_shift(size_t fft_length)
29 : d_fftlen(fft_length),
30 d_lenpos(fft_length / 2 + (fft_length % 2)),
31 d_lenneg(fft_length / 2),
32 d_buf(fft_length)
33 {
34 }
35
36 /*! performs the cyclic shift on a vector v
37 */
38 void shift(std::vector<T>& v) { shift(&v.front(), v.size()); }
39
40 /*! performs the cyclic shift on an array
41 */
42 void shift(T* data, size_t fft_len)
43 {
44 resize(fft_len);
45 std::copy_n(data, d_lenpos, d_buf.begin());
46 std::copy_n(data + d_lenpos, d_lenneg, data);
47 std::copy_n(d_buf.begin(), d_lenpos, data + d_lenneg);
48 }
49
50 /*! if needed adjusts the buffer size to a new fft length
51 */
52 void resize(size_t fft_length)
53 {
54 if (d_fftlen == fft_length)
55 return;
56 d_fftlen = fft_length;
57 d_lenpos = d_fftlen / 2 + (d_fftlen % 2);
58 d_lenneg = d_fftlen / 2;
59 assert(d_lenpos + d_lenneg == d_fftlen);
60 d_buf.resize(d_lenpos);
61 }
62
63protected:
64private:
65 size_t d_fftlen; // FFT length
66 size_t d_lenpos; // number of FFT bins with positive frequencies
67 size_t d_lenneg; // number of FFT bins with negative frequencies
68 std::vector<T> d_buf; // buffer used for cyclic shift
69};
70
71} // namespace fft
72} // namespace gr
73#endif // INCLUDED_FFT_FFT_SHIFT_H
reorder FFT results which are ordered from 0 to 1 in normalized frequency to -0.5 to 0....
Definition: fft_shift.h:26
fft_shift(size_t fft_length)
Definition: fft_shift.h:28
void resize(size_t fft_length)
Definition: fft_shift.h:52
void shift(std::vector< T > &v)
Definition: fft_shift.h:38
void shift(T *data, size_t fft_len)
Definition: fft_shift.h:42
GNU Radio logging wrapper.
Definition: basic_block.h:29
Definition: cc_common.h:35