MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / fourier1D

Method fourier1D

ij/src/main/java/ij/process/FHT.java:127–159  ·  view source on GitHub ↗

Calculates the Fourier amplitudes of an array, based on a 1D Fast Hartley Transform. With no Window function, if the array size is a power of 2, the input function should be either periodic or the data at the beginning and end of the array should approach the same value (the periodic continuation sh

(float[] data, int windowType)

Source from the content-addressed store, hash-verified

125 * of i/(2*results.length*dx).
126 */
127 public float[] fourier1D(float[] data, int windowType) {
128 int n = data.length;
129 int size = 2;
130 while (size<n) size *= 2; // find power of 2 where the data fit
131 float[] y = new float[size]; // leave the original data untouched, work on a copy
132 System.arraycopy(data, 0, y, 0, n); // pad to 2^n-size
133 double sum = 0;
134 if (windowType != NO_WINDOW) {
135 for (int x=0; x<n; x++) { //calculate non-normalized window function
136 double z = (x + 0.5) * (2 * Math.PI / n);
137 double w = 0;
138 if (windowType == HAMMING)
139 w = 0.54 - 0.46 * Math.cos(z);
140 else if (windowType == HANN)
141 w = 1. - Math.cos(z);
142 else if (windowType == FLATTOP)
143 w = 1. - 1.90796 * Math.cos(z) + 1.07349 * Math.cos(2*z) - 0.18199 * Math.cos(3*z);
144 else
145 throw new IllegalArgumentException("Invalid Fourier Window Type");
146 y[x] *= w;
147 sum += w;
148 }
149 } else
150 sum = n;
151 for (int x=0; x<n; x++) //normalize
152 y[x] *= (1./sum);
153 transform1D(y); //transform
154 float[] result = new float[size/2];
155 result[0] = (float)Math.sqrt(y[0]*y[0]);
156 for (int x=1; x<size/2; x++)
157 result[x] = (float)Math.sqrt(y[x]*y[x]+y[size-x]*y[size-x]);
158 return result;
159 }
160
161 /** Performs an optimized 1D Fast Hartley Transform (FHT) of an array.
162 * Array size must be a power of 2.

Callers 1

fourierArrayMethod · 0.80

Calls 3

transform1DMethod · 0.95
arraycopyMethod · 0.45
sqrtMethod · 0.45

Tested by

no test coverage detected