# 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 random map can also vary in time. It is then a random field phi(f, t) smoothed in frequency over a chosen number of bands and in time over a chosen time scale, and B is synthesized band by band as y(t) = Re sum_k exp(i phi_k(t)) z_k(t). Each band is narrow, so its subband signal is computed at a reduced sample rate from its slice of the spectrum, rotated, and transformed back, which keeps the cost small even with thousands of bands. A phase that changes in time is frequency modulation: band k shifts by phi_k'(t) / 2 pi, and for a field of standard deviation s and time scale T the typical shift is s / (2 pi T), which the app reports. The expectation is that slow variation (seconds) is inaudible and fast variation (tens of milliseconds) is heard as warble or roughness, with the transition near the pitch threshold of about 1 Hz for low tones. The controls are the window width sigma (0.3 ms to 50 ms), the phase map (smoothed random with adjustable smoothing in frequency and in time, strength, and seed; a pure delay as a control; or a chirp whose group delay grows linearly with frequency), and the source. The app plots the map over time and frequency, the magnitude response and group delay of the equivalent filter (at the middle of the clip when the map varies), 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).