-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1D signal Fourier and Inverse Fourier transform filter.
- Loading branch information
ArminTaheri
committed
Aug 1, 2017
1 parent
a996c28
commit d4871bd
Showing
8 changed files
with
2,774 additions
and
168 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { PixpipeContainer } from './PixpipeContainer'; | ||
|
||
class Signal1D extends PixpipeContainer { | ||
constructor() { | ||
super(); | ||
this._type = Signal1D.TYPE(); | ||
this.setMetadata('length', 0); | ||
} | ||
|
||
static TYPE() { | ||
return 'SIGNAL1D'; | ||
} | ||
|
||
getData() { | ||
return this._data; | ||
} | ||
|
||
setData(array, deepCopy = false) { | ||
if (deepCopy) { | ||
this._data = new array.constructor(array); | ||
} else { | ||
this._data = array; | ||
} | ||
|
||
this.setMetadata('length', array.length); | ||
} | ||
|
||
clone(){ | ||
const copy = new Signal1D(); | ||
if (this._data) { | ||
copy.setData(this._data, true); | ||
} | ||
return copy; | ||
} | ||
|
||
hollowClone(){ | ||
const copy = new Signal1D(); | ||
const length = this.getMetadata('length'); | ||
copy.setData( new Float32Array(length).fill(0) ); | ||
return copy | ||
} | ||
} | ||
|
||
export { Signal1D } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import { Filter } from '../core/Filter.js'; | ||
import QeegModFileParser from 'qeegmodfileparser'; | ||
import { QeegModFileParser } from 'qeegmodfile'; | ||
|
||
|
||
class EegModDecoder extends Filter { | ||
|
||
constructor() { | ||
super(); | ||
this.addInputValidator(0, ArrayBuffer); | ||
this.setMetadata("debug", false); | ||
|
||
// a soon-to-be DataView to read the input buffer | ||
this._view = null; | ||
} | ||
|
||
_run(){ | ||
var inputBuffer = this._getInput(0); | ||
|
||
if(!inputBuffer){ | ||
console.warn("EegModDecoder requires an ArrayBuffer as input \"0\". Unable to continue."); | ||
return; | ||
} | ||
|
||
var modParser = new QeegModFileParser(); | ||
modParser.setRawData( inputBuffer ); | ||
var qeegData = modParser.parse(); | ||
|
||
if( qeegData ){ | ||
this._output[0] = qeegData; | ||
} | ||
|
||
} | ||
|
||
} /* END of class EegModDecoder */ | ||
|
||
export { EegModDecoder } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import ndarray from 'ndarray'; | ||
import ft from 'ndarray-fft'; | ||
|
||
import { Filter } from '../core/Filter'; | ||
import { Signal1D } from '../core/Signal1D'; | ||
|
||
const DIRECTIONS = { | ||
'FORWARD': 1, | ||
'INVERSE': -1, | ||
}; | ||
|
||
class BaseFourierSignalFilter extends Filter { | ||
constructor(direction) { | ||
super(); | ||
this.direction = direction; | ||
if (DIRECTIONS[this.direction] === undefined) { | ||
throw new Error(`${this.direction} is not a valid fourier transform direction. Please try one of: ${Object.keys(DIRECTIONS)}`); | ||
} | ||
this.addInputValidator(0, Signal1D); | ||
} | ||
_run() { | ||
if( ! this.hasValidInput()){ | ||
console.warn("A filter of type BaseFourierSignalFilter requires 1 input of Signal1D."); | ||
return; | ||
} | ||
const inputSignal = this._getInput(0); | ||
const length = inputSignal.getMetadata('length'); | ||
const real = ndarray(inputSignal.clone().getData(), [length]); | ||
const img = ndarray(inputSignal.hollowClone().getData(), [length]); | ||
this.setMetadata('direction', this.direction); | ||
|
||
ft(DIRECTIONS[this.direction], real, img); | ||
this._output[0] = new Signal1D(); | ||
this._output[0].setData(real.data); | ||
this._output[1] = new Signal1D(); | ||
this._output[1].setData(img.data); | ||
} | ||
} | ||
|
||
class ForwardFourierSignalFilter extends BaseFourierSignalFilter { | ||
constructor() { | ||
super('FORWARD'); | ||
} | ||
} | ||
|
||
class InverseFourerSignalFilter extends BaseFourierSignalFilter { | ||
constructor() { | ||
super('INVERSE'); | ||
} | ||
} | ||
|
||
export { ForwardFourierSignalFilter, InverseFourerSignalFilter } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters