({{, (RefLink[AudioSpectralMap, paclet:ref/AudioSpectralMap])[f,audio] 
transforms audio by applying the function f to its short-time Fourier transform.}, {, (RefLink[AudioSpectralMap, paclet:ref/AudioSpectralMap])[f,{(Subscript[audio, 1]),…}]
applies the function f to the list of short-time Fourier transforms of all (Subscript[audio, i]).}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[AudioSpectralMap, paclet:ref/AudioSpectralMap]) can be used to arbitrarily modify the signal both in the time domain and the frequency domain. Spectral filters can be used to diminish, highlight or modify specific frequencies at specific times, e.g. removing noise.

(RefLink[AudioSpectralMap, paclet:ref/AudioSpectralMap]) applies the function f to the short-time Fourier transform and computes the inverse using the overlap-add method.

Function f takes values of short-time Fourier transform as the first argument. Optionally, frequency and time can be given to f as the second and third arguments:

For multichannel audio objects, the transformation is performed separately on each channel.

When multiple audio signals are present, #Value is a list of values. Use #Value[[i]] for (Subscript[audio, i]).

(RefLink[AudioSpectralMap, paclet:ref/AudioSpectralMap]) accepts a (RefLink[PartitionGranularity, paclet:ref/PartitionGranularity]) option that can specify the duration of each partition and the offset, as well as the smoothing window.

OpenersPrimaryExamplesSection(Spacer1)Examples  (13)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Spectral filtering of an audio signal:

AudioSpectralMap[#Value^1.5&,]//AudioNormalize

OpenersExampleSection1(Spacer1)Scope  (2)

Multiply each spectral component by its frequency:

a=;

AudioSpectralMap[#Value*#Frequency&,a]//AudioNormalize

Multiply each spectral component by the time:

AudioSpectralMap[#Value*#Time&,a]//AudioNormalize

Mutate between two sounds:

a1=;a2=;

Multiply the two short-time Fourier transforms:

AudioSpectralMap[Times@@#Value&,{a1,a2}]

Use the magnitude of the first audio and the phase of the second:

AudioSpectralMap[Abs@#Value[[1]]*Exp[-I Arg@#Value[[2]]]&,{a1,a2}]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)PartitionGranularity  (1)

By default, automatic partitioning suitable for spectral filtering is used:

a=;

AudioSpectralMap[#Value^1.5&,a]//AudioNormalize

Specify the partition size:

AudioSpectralMap[#Value^1.5&,a,PartitionGranularity->(Quantity[80, "ms", milliseconds, "Milliseconds"])]//AudioNormalize

Specify the partition size, offset and smoothing window:

AudioSpectralMap[#Value^1.5&,a,PartitionGranularity->{.08,.005,HannWindow}]//AudioNormalize

OpenersExampleSection3(Spacer1)Applications  (8)

Denoise an audio signal by eliminating all components with small amplitude:

a=;
Spectrogram[a]

AudioSpectralMap[If[Abs@#Value<4,0.,#Value]&,a]

Spectrogram[%]

Create a lowpass filter by removing components smaller than 1000Hz:

a=AudioGenerator["White",1,SampleRate->8000];

Spectrogram[a]

AudioSpectralMap[#Value (1-UnitStep[#Frequency-1000])&,a]

Spectrogram[%]

Create a highpass filter:

AudioSpectralMap[#Value UnitStep[#Frequency-1000]&,a]

Spectrogram[%]

Zero out all the components at times smaller than 0.5 seconds:

a=AudioGenerator["White",1,SampleRate->8000];

Spectrogram[a]

AudioSpectralMap[#Value (UnitStep[#Time-.5])&,a]

Spectrogram[%]

Assign a random phase to all the components to achieve a whisper effect:

a = ExampleData[{"Audio","Apollo11SmallStep"},"Audio"];
AudioSpectralMap[#Value Exp[I RandomReal[2Pi]]&,a]

Assign a phase equal to zero to all the components to achieve a robot-like result:

a = ExampleData[{"Audio","Apollo11SmallStep"},"Audio"];
AudioSpectralMap[Abs[#Value]&,a,PartitionGranularity->(Quantity[30, "ms", milliseconds, "Milliseconds"])]

Lower the amplitude of quiet components, effectively performing a simple denoise:

apollo = ExampleData[{"Audio","Apollo11SmallStep"},"Audio"];

f[value_]:=((value Abs[value])/(Abs[value]+10))

Plot[f[value],{value,0,10}]

AudioSpectralMap[f,apollo]

Completely zero out the quiet components:

g[value_]:=If[Abs[((value Abs[value])/(Abs[value]+10))]<2,0,value]

Plot[g[value],{value,0,10}]

AudioSpectralMap[g,apollo]

Create a time-dependent highpass filter:

a=AudioGenerator["White",SampleRate->8000];

f[value_,freq_,time_]:=value(Tanh[(freq-2000*(1-time))]/2+.5)

AudioSpectralMap[f,a]//AudioNormalize

Spectrogram[%]

Denoise a signal by subtracting a noise profile:

apollo = ExampleData[{"Audio","Apollo11SmallStep"},"Audio"]

Spectrogram[apollo]

Trim a part of the signal that contains only noise:

noise=AudioTrim[apollo,{4,5}]

Compute the magnitude spectrum of the noise:

noiseSpectrum=Abs[Fourier[First@AudioData[noise],FourierParameters->{1,-1}]];

Smooth the result:

smoothedNoiseSpectrum=MeanFilter[noiseSpectrum,20];

Create an interpolating function on the frequency domain using the smoothed noise spectrum:

len=Floor[Length[noiseSpectrum]/2];f=Interpolation[Thread[{Array[#&,len,{0.,11025}],smoothedNoiseSpectrum[[;;len]]}]]

Plot[f[x],{x,0,10000}]

Subtract from each component the corresponding noise spectrum magnitude:

AudioSpectralMap[Clip[(Abs[#Value]-f[#Frequency]),{0,Infinity}]*Exp[-I Arg@#Value]&,apollo]

Spectrogram[%]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

Apply identity to each spectral component:

a=ExampleData[{"Audio","Apollo11SmallStep"},"Audio"];

AudioSpectralMap[Identity,a]

This operation is not an identity operation, due to the overlap and add during the inverse transform:

%==a

However, the result only has small discrepancies compared to the original signal:

{Mean[#],StandardDeviation[#]}&[AudioSpectralMap[Identity,a]-a]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[SpectrogramArray, paclet:ref/SpectrogramArray])  ▪  (RefLink[AudioSpectralTransformation, paclet:ref/AudioSpectralTransformation])  ▪  (RefLink[LowpassFilter, paclet:ref/LowpassFilter])  ▪  (RefLink[Fourier, paclet:ref/Fourier])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Audio Processing, paclet:guide/AudioProcessing])}})}})