STIR 6.4.0
fftshift.h
Go to the documentation of this file.
1#ifndef __stir_numerics_fftshift_H__
2#define __stir_numerics_fftshift_H__
3/*
4 Copyright (C) 2025, University College London
5 This file is part of STIR.
6
7 SPDX-License-Identifier: Apache-2.0
8
9 See STIR/LICENSE.txt for details
10*/
25
26#include "stir/Array.h"
27#include <complex>
28#include <utility> // for std::swap
29
30START_NAMESPACE_STIR
31
33template <typename T>
34inline void
35fftshift(Array<1, T>& a, int size)
36{
37 for (int i = 0; i < size / 2; ++i)
38 std::swap(a[i], a[size / 2 + i]);
39}
40
42template <typename T>
43inline void
44fftshift(Array<2, std::complex<T>>& a, int size)
45{
46 // swap left/right halves across all rows
47 for (int i = 0; i < size; ++i)
48 for (int j = 0; j < size / 2; ++j)
49 std::swap(a[i][j], a[i][size / 2 + j]);
50
51 // swap top/bottom halves across all columns
52 for (int i = 0; i < size; ++i)
53 for (int j = 0; j < size / 2; ++j)
54 std::swap(a[j][i], a[size / 2 + j][i]);
55}
56
57END_NAMESPACE_STIR
58#endif
defines the stir::Array class for multi-dimensional (numeric) arrays
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
void fftshift(Array< 1, T > &a, int size)
In-place 1D fftshift: swap halves [0..N/2-1] <-> [N/2..N-1].
Definition fftshift.h:35