view src/samer/units/RescaledIFT.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY;
 *	without even the implied warranty of MERCHANTABILITY or
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.units;

import samer.core.*;
import samer.maths.*;
import samer.tools.*;
import samer.functions.*;

/**
	Inverts a given FFT using an alternative magnitude spectrum
  */

public class RescaledIFT extends FFT implements Task
{
	Vec			mag;
	FFT			ft;
	double	k[];
	VVector out;

	public RescaledIFT(FFT ft, Vec mag) throws Exception
	{
		super(ft.size());
		this.ft=ft;
		this.mag=mag;
		k=new double[N];
		invert();
		out=new VVector("ift.output", real);
	}

	public VVector output() { return out; }
	
	public void dispose() {}
	public void starting() {}
	public void stopping() {}
	public void run() {
		Vec.Iterator mit=mag.iterator();
		int 		i, j;

		for (i=0, j=N-1; mit.more(); i++, j--)
			k[j]=k[i]=mit.next()/abs(ft.real[i],ft.imag[i]);
		for (; i<=N/2; i++, j--) k[i]=k[j]=0;

		for (i=0; i<N; i++) {
			j=bitrev[i];
			real[j]  = k[i]*ft.real[i];
			imag[j] = k[i]*ft.imag[i];
		}
		calculate();
		out.changed();
	}

	private static double abs(double x,double y) { return Math.sqrt(x*x+y*y); }
}