plectrum

Plectrum: instrument tuner for Android
Log | Files | Refs | README | LICENSE

GaussWindow.java (2576B)


      1 /*
      2 *      _______                       _____   _____ _____  
      3 *     |__   __|                     |  __ \ / ____|  __ \ 
      4 *        | | __ _ _ __ ___  ___  ___| |  | | (___ | |__) |
      5 *        | |/ _` | '__/ __|/ _ \/ __| |  | |\___ \|  ___/ 
      6 *        | | (_| | |  \__ \ (_) \__ \ |__| |____) | |     
      7 *        |_|\__,_|_|  |___/\___/|___/_____/|_____/|_|     
      8 *                                                         
      9 * -------------------------------------------------------------
     10 *
     11 * TarsosDSP is developed by Joren Six at IPEM, University Ghent
     12 *  
     13 * -------------------------------------------------------------
     14 *
     15 *  Info: http://0110.be/tag/TarsosDSP
     16 *  Github: https://github.com/JorenSix/TarsosDSP
     17 *  Releases: http://0110.be/releases/TarsosDSP/
     18 *  
     19 *  TarsosDSP includes modified source code by various authors,
     20 *  for credits and info, see README.
     21 * 
     22 */
     23 
     24 /*
     25  *  Copyright (c) 2007 - 2008 by Damien Di Fede <ddf@compartmental.net>
     26  *
     27  *   This program is free software; you can redistribute it and/or modify
     28  *   it under the terms of the GNU Library General Public License as published
     29  *   by the Free Software Foundation; either version 2 of the License, or
     30  *   (at your option) any later version.
     31  *
     32  *   This program is distributed in the hope that it will be useful,
     33  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     34  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     35  *   GNU Library General Public License for more details.
     36  *
     37  *   You should have received a copy of the GNU Library General Public
     38  *   License along with this program; if not, write to the Free Software
     39  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     40  */
     41 
     42 package be.tarsos.dsp.util.fft;
     43 
     44 /**
     45  * A Gauss window function.
     46  * 
     47  * @author Damien Di Fede
     48  * @author Corban Brook
     49  * @see <a href="http://en.wikipedia.org/wiki/Window_function#Gauss_windows">The
     50  *      Gauss Window</a>
     51  */
     52 public class GaussWindow extends WindowFunction {
     53 	double alpha;
     54 
     55 	/**
     56 	 * Constructs a Gauss window function.
     57 	 * 
     58 	 * @param alpha
     59 	 */
     60 	public GaussWindow(double alpha) {
     61 		if (alpha < 0.0 || alpha > 0.5) {
     62 			new IllegalArgumentException(
     63 					"Range for GaussWindow out of bounds. Value must be <= 0.5");
     64 		} else {
     65 			this.alpha = alpha;
     66 		}
     67 	}
     68 
     69 	/** Constructs a Gauss window with a default alpha value of 0.25 */
     70 	public GaussWindow() {
     71 		this(0.25);
     72 	}
     73 
     74 	protected float value(int length, int index) {
     75 		return (float) Math.pow(Math.E,	-0.5 * Math.pow((index - (length - 1) / (double) 2)	/ (this.alpha * (length - 1) / (double) 2),(double) 2));
     76 	}
     77 }