Swap the left and right halves of the vector. - Java java.lang

Java examples for java.lang:Math Matrix

Description

Swap the left and right halves of the vector.

Demo Code


//package com.java2s;

public class Main {
    /**/*from ww  w  .  j a  va 2 s. com*/
     * Swap the left and right halves of the vector.
     * 
     * This function swaps the left part of the signal with the right part of
     * the signal.
     * 
     * This operation, known as 'fftshift' in the Matlab Signal Processing
     * Toolbox, can be used before computing the FFT to simplify the phase
     * relationship of the resulting spectrum.
     */
    public static void shift(double[] data) {
        for (int j = 0; j < data.length / 2; j++) {
            double t = data[j];
            data[j] = data[j + data.length / 2];
            data[j + data.length / 2] = t;
        }
    }
}

Related Tutorials