# Phase Perception 2 A web app for testing whether a sound still sounds the same when the phases of its frequency components are changed while their envelopes are kept. It extends [phase-perception](../phase-perception/), which asked the same question of steady tones with a fixed set of harmonics, to arbitrary sounds: clicks, noise bursts, plucked strings, loaded audio files, and microphone recordings. ## What it does The source sound A is split into overlapping Gaussian frequency bands, the short-time Fourier transform viewed as a filter bank with a hop of one sample. Band k has a Gaussian response of width sigma_f = 1 / (2 pi sigma) centered at f_k = k sigma_f, where sigma is the window width in time, and the responses are normalized to sum to one so that adding the bands back together reproduces the signal exactly. Sound B is B(t) = Re sum_k exp(i phi_k) z_k(t) where z_k is the complex subband signal and phi_k is the phase map evaluated at the band center. Every subband envelope |z_k(t)| is unchanged, so A and B have the same spectrogram at the analysis resolution, but their waveforms differ. Because phi_k does not depend on time, the operation is a linear time-invariant filter with response G(f) = sum_k exp(i phi_k) H_k(f), and the app computes it that way, with one FFT pair, in a Web Worker. The controls are the window width sigma (0.3 ms to 50 ms), the phase map (smoothed random with adjustable smoothing and strength, a pure delay as a control, or a chirp whose group delay grows linearly with frequency), and the source. The app plots the map, the magnitude response and group delay of the equivalent filter, the waveforms of A and B with a zoom, and the spectrograms of A and B on a shared scale. A and B can be played singly or in sequence with the same gain. The design and the reasoning behind it are described in [docs/spectrogram-phase-proposal.md](../phase-perception/docs/spectrogram-phase-proposal.md) in the first app's repository. ## Two constraints worth knowing The phase map must change slowly from one band to the next. Neighbouring bands overlap, and where their phases disagree their contributions partly cancel, which puts notches in the magnitude response. The app reports the largest magnitude deviation and warns above 1 dB. For a pure delay of tau the magnitude is exp(-tau^2 / (2 sigma^2)), so delays are limited to a fraction of the window width. In general the group delay that any map can impose without changing magnitudes is bounded by roughly sigma, which is why the window width is the parameter that controls how much transients are smeared. Group delay peaks beyond roughly 1 ms have been reported to be audible on impulsive sounds over headphones (Blauert and Laws, 1978), and steady sounds are far less sensitive. The expectation is therefore that phase maps are inaudible on sustained sounds for any window and on transients for short windows, and audible as a softening of transients for windows of several milliseconds and beyond. ## Running npm install npm run dev Then open the printed URL. `npm run build` produces a static site in `dist/` with a relative base path. Microphone recording needs a secure context (https or localhost).