1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
#include "ltfat.h"
#include "ltfat_types.h"
/* This routines changes the center of a vector from the beginning
* to the middle.
*
* f : Real valued input array.
* L : Length of input array
* W : Number of arrays to transform.
* h : Output, same size as input.
*
* For the typical use of a single vector, set W=1.
*
* This function works in the exact same way as the Matlab command
*
* h = fftshift(f,1);
*
*/
LTFAT_EXTERN void
LTFAT_NAME(fftshift_r)(const LTFAT_REAL *f, const ltfatInt L, LTFAT_REAL *h)
{
ltfatInt ii;
const div_t domod=div(L,2);
for (ii=0; ii<domod.quot; ii++)
{
h[ii]=f[ii+domod.quot+domod.rem];
}
for (ii=0; ii<domod.quot+domod.rem; ii++)
{
h[ii+domod.quot]=f[ii];
}
}
/* This does the reverse of fftshift. When L is even, this function is
* identical to fftshift, but for odd L there is a difference.
*
* f : Real valued input array.
* L : Length of input array
* W : Number of arrays to transform.
* h : Output, same size as input.
*
* For the typical use of a single vector, set W=1.
*
* This function works in the exact same way as the Matlab command
*
* h = ifftshift(f,1);
*
*/
LTFAT_EXTERN void
LTFAT_NAME(ifftshift_r)(const LTFAT_REAL *f, const ltfatInt L, LTFAT_REAL *h)
{
ltfatInt ii;
div_t domod;
domod=div(L,2);
for (ii=0; ii<domod.quot+domod.rem; ii++)
{
h[ii]=f[ii+domod.quot];
}
for (ii=0; ii<domod.quot; ii++)
{
h[ii+domod.quot+domod.rem]=f[ii];
}
}
/* This routine changes an FIR window to a LONG window.
*
* Input parameters:
* f : Real valued input array.
* Lfir : Length of input array
* Llong : Length of output array
* h : Output array
*/
LTFAT_EXTERN void
LTFAT_NAME(fir2long_r)(const LTFAT_REAL *f, const ltfatInt Lfir, const ltfatInt Llong,
LTFAT_REAL *h)
{
const div_t domod=div(Lfir,2);
/* ---- In the odd case, the additional element is kept in the first half. ---*/
for (ltfatInt ii=0; ii<domod.quot+domod.rem; ii++)
{
h[ii]=f[ii];
}
for (ltfatInt ii=domod.quot+domod.rem; ii<Llong-domod.quot; ii++)
{
h[ii]=0.0;
}
const ltfatInt ss=Llong-Lfir;
for (ltfatInt ii=domod.quot+domod.rem; ii<Lfir; ii++)
{
h[ii+ss]=f[ii];
}
}
/* This routine changes an FIR window to a LONG window.
*
* Input parameters:
* f : Complex valued input array.
* Lfir : Length of input array
* Llong : Length of output array
* h : Output array
*/
LTFAT_EXTERN void
LTFAT_NAME(fir2long_c)(const LTFAT_COMPLEX *f, const ltfatInt Lfir, const ltfatInt Llong,
LTFAT_COMPLEX *h)
{
const div_t domod=div(Lfir,2);
/* ---- In the odd case, the additional element is kept in the first half. ---*/
for (ltfatInt ii=0; ii<domod.quot+domod.rem; ii++)
{
h[ii]=f[ii];
}
for (ltfatInt ii=domod.quot+domod.rem; ii<Llong-domod.quot; ii++)
{
h[ii] = (LTFAT_COMPLEX) 0.0;
}
const ltfatInt ss=Llong-Lfir;
for (ltfatInt ii=domod.quot+domod.rem; ii<Lfir; ii++)
{
h[ii+ss]=f[ii];
}
}
/* This routine changes a LONG window to an FIR window.
*
* Input parameters:
* f : Real valued input array.
* Llong : Length of input array
* Lfir : Length of output array
* h : Output array
*/
LTFAT_EXTERN void
LTFAT_NAME(long2fir_r)(const LTFAT_REAL *f, const ltfatInt Llong, const ltfatInt Lfir, LTFAT_REAL *h)
{
const div_t domod=div(Lfir,2);
/* ---- In the odd case, the additional element is kept in the first half. ---*/
for (ltfatInt ii=0; ii<domod.quot+domod.rem; ii++)
{
h[ii]=f[ii];
}
const ltfatInt ss=Llong-Lfir;
for (ltfatInt ii=domod.quot+domod.rem; ii<Lfir; ii++)
{
h[ii]=f[ii+ss];
}
}
LTFAT_EXTERN void
LTFAT_NAME(long2fir_c)(const LTFAT_COMPLEX *f, const ltfatInt Llong, const ltfatInt Lfir, LTFAT_COMPLEX *h)
{
const div_t domod=div(Lfir,2);
/* ---- In the odd case, the additional element is kept in the first half. ---*/
for (ltfatInt ii=0; ii<domod.quot+domod.rem; ii++)
{
h[ii]=f[ii];
}
const ltfatInt ss=Llong-Lfir;
for (ltfatInt ii=domod.quot+domod.rem; ii<Lfir; ii++)
{
h[ii]=f[ii+ss];
}
}
|