Skip to content

jobo322/apodization

Repository files navigation

Apodization and window functions

NPM version build status Test coverage npm download

A package to compose and apply window functions.

Installation

$ npm i apodization

Usage

It is possible to import the functions directly. Those function accepts an object with options and returns a function (i: number) => number to avoid constants calculation for each call.

import { lorentzToGauss } from 'apodization';
const gm = lorentzToGauss({ gaussianHz: 0.2, exponentialHz: 0, center: 0.5, length: 500, dw = 0.01 });
const value = gm(250); //returns the max value of the gaussian;

It is possible to use the getFunction

import { getFunction } from 'apodization';

const gm = getFunction({ 
  kind: 'lorentzToGauss', 
  options: { 
    gaussianHz: 0.2, 
    exponentialHz: 0, 
    center: 0.5, 
    length: 500, 
    dw = 0.01
  }
});
const value = gm(250); //returns the max value of the gaussian;

Current supported shapes:

Exponential Lorentz to gauss

It is possible to apply a window function directly to data (number[]). It does not change the original data by default but it is possible to pass an array in output property.

import { applyWindow, exponential } from 'apodization';
const data = [1,2,3,4,5];
const exponentialFunc = exponential({ dw: 0.1, lb: 0.2, start: 0 })
const result = applyWindow(data, {
  func: exponential,
  start: 0,
  output: data //inplace modification
});

It is possible to compose a window function by:

import { compose } from 'apodization';

const lorentzToGaussShapeOptions = { 
  dw = 0.01,
  center: 0.5, 
  length: 500,
  gaussianHz: 0.2, 
  exponentialHz: 0, 
};

const exponentialShapeOptions = {
  dw = 0.01,
  lb = 2,
}

const func = compose({
  length: 500,
  shapes: [
    {
      start: 0,
      shape: {
        kind: 'lorentzToGauss',
        options: lorentzToGaussShapeOptions,
      }
    },
    {
      start: 0,
      shape: {
        kind: 'exponential',
        options: exponentialShapeOptions,
      }
    }
  ]
});

console.log(func(250)); //value of window function of index 250

License

MIT