Mercurial > hg > ugly-duckling
changeset 130:8aa1ff061503
Scaling
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Thu, 16 Mar 2017 11:54:48 +0000 |
parents | 161af71c80d4 |
children | 4eb3cc32f6c0 e50248f9cda3 |
files | src/app/spectrogram/Spectrogram.ts |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/app/spectrogram/Spectrogram.ts Thu Mar 16 10:35:53 2017 +0000 +++ b/src/app/spectrogram/Spectrogram.ts Thu Mar 16 11:54:48 2017 +0000 @@ -13,6 +13,7 @@ private fft: RealFft; private real: Float32Array; private nCols: number; + private columnHeight: number; private window: Float32Array; constructor(samples: Float32Array, options: Framing & Object) { @@ -21,6 +22,7 @@ this.framing = options; this.real = new Float32Array(this.framing.blockSize); this.nCols = Math.floor(this.samples.length / this.framing.stepSize); //!!! not correct + this.columnHeight = Math.round(this.framing.blockSize / 2) + 1; this.fft = new KissRealFft(this.framing.blockSize); this.window = hann(this.framing.blockSize); } @@ -30,7 +32,7 @@ } getColumnHeight(): number { - return Math.floor(this.framing.blockSize * 0.5) + 1; + return this.columnHeight; } getColumn(n: number): Float32Array { @@ -54,10 +56,12 @@ const h = this.getColumnHeight(); const col = new Float32Array(h); + const scale = 1.0 / Math.sqrt(sz); for (let i = 0; i < h; ++i) { - const real: number = complex[i * 2]; - const imaginary: number = complex[i * 2 + 1]; - col[i] = real * real + imaginary * imaginary; + const re : number = complex[i*2] * scale; + const im : number = complex[i*2+1] * scale; + const mag = Math.sqrt(re * re + im * im); + col[i] = mag; } return col;