({{, (RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed])[f,wd]
applies the function f to the arrays of coefficients and indices of a (RefLink[ContinuousWaveletData, paclet:ref/ContinuousWaveletData]) or (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]) object.}, {, (RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed])[f,dwd,wind]
applies f to the (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]) coefficients specified by wind.}, {, (RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed])[f,cwd,octvoc]
applies f to the (RefLink[ContinuousWaveletData, paclet:ref/ContinuousWaveletData]) coefficients specified by octvoc.}})

OpenersNotesSection(Spacer1)Details

(RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed]) takes a (RefLink[ContinuousWaveletData, paclet:ref/ContinuousWaveletData]) or (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]) object and returns an object of the same type.

For dwd with coefficients {(Subscript[wind, 1])->(Subscript[coef, 1]),…}, (RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed])[f,dwd] effectively corresponds to (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData])[{(Subscript[wind, 1])->f[(Subscript[coef, 1]),(Subscript[wind, 1])],…},…].

For cwd with coefficients {{(Subscript[oct, 1]),(Subscript[voc, 1])}->(Subscript[coef, 1]),…}, (RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed])[f,cwd] effectively corresponds to (RefLink[ContinuousWaveletData, paclet:ref/ContinuousWaveletData])[{{(Subscript[oct, 1]),(Subscript[voc, 1])}->f[(Subscript[coef, 1]),{(Subscript[oct, 1]),(Subscript[voc, 1])}],…},…].

Each f[(Subscript[coef, i]),(Subscript[wind, i])] should return an array or (RefLink[Image, paclet:ref/Image]) of the same dimensions as (Subscript[coef, i]).

For (RefLink[Sound, paclet:ref/Sound]) and (RefLink[SampledSoundList, paclet:ref/SampledSoundList]), each (Subscript[coef, i]) is given as a list of vectors, each corresponding to a channel of sound samples.

The wavelet index convention is the same as explained in (RefLink[ContinuousWaveletData, paclet:ref/ContinuousWaveletData]) and (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (25)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Rescale all coefficients of a discrete wavelet transform by 20:

dwd=DiscreteWaveletTransform[{0,1,2,0}];

WaveletMapIndexed[20#&,dwd]

(RefLink[Normal, paclet:ref/Normal]) gives the array of coefficients:

Normal[%]

Compare with the unmodified coefficients:

Normal[dwd]

Amplify the {1} coefficient of the stationary wavelet transform of an image:

swt=StationaryWaveletTransform[]

WaveletMapIndexed[ImageMultiply[#,10]&,swt,{1}]

The inverse wavelet transform gives an image with vertical edges sharpened:

{InverseWaveletTransform[%],}

OpenersExampleSection1(Spacer1)Scope  (11)

OpenersExampleSubsection0(Spacer1)Basic Uses  (3)

Apply an arbitrary function to all coefficients of a discrete wavelet transform:

WaveletMapIndexed[Map[f,#]&,DiscreteWaveletTransform[{0,1,2,0}]]//Normal

Apply a symbolic function that also depends on the wavelet index for each coefficient vector:

WaveletMapIndexed[Function[{v,wind},Map[f[#,wind]&,v]],DiscreteWaveletTransform[{0,1,2,0}]]//Normal

(RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed]) operates on (RefLink[ContinuousWaveletData, paclet:ref/ContinuousWaveletData]) or (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]):

{DiscreteWaveletTransform[{0,1,2,0}],ContinuousWaveletTransform[{1,2,3,4}]}

The result is a wavelet data object of the same type:

{dwd,cwd}=Map[WaveletMapIndexed[c|->c+0.2,#]&,%]

The modified data can be used in other wavelet functions such as inverse wavelet transforms:

{InverseWaveletTransform[dwd],InverseContinuousWaveletTransform[cwd]}

OpenersExampleSubsection1(Spacer1)Coefficient Specification  (4)

Transform only specified coefficients in (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]):

dwd=DiscreteWaveletTransform[{0,1,2,0}]

Apply a function to detail coefficients only, using the index pattern {___, 1}:

WaveletMapIndexed[c|->Map[f,c],dwd,{___,1}]//Normal

Apply a function to coarse coefficients only, using the index pattern {___, 0}:

WaveletMapIndexed[c|->Map[f,c],dwd,{___,0}]//Normal

Transform only specified coefficients in a (RefLink[ContinuousWaveletData, paclet:ref/ContinuousWaveletData]):

cwd=ContinuousWaveletTransform[{1,2,5},Automatic,{3,2}]

Apply a function to coefficients in the first octave {1,_} only:

WaveletMapIndexed[c|->Map[f,c],cwd,{1,_}]//Normal

Apply a function to all coefficients except those in the second octave, first voice {2,1}:

WaveletMapIndexed[c|->Map[f,c],cwd,Except[{2,1}]]//Normal

The function f can depend on the wavelet index as its second argument:

WaveletMapIndexed[{c,wind}|->Length[wind]*c,DiscreteWaveletTransform[{0,1,2,0}]]//Normal

Define a function with an arbitrary dependence on the wavelet index:

f[c_,wind_]:=c
f[c_,{1,2}]:=0c
f[c_,{1,4}]:=Chop[c,0.5]

Apply the function to continuous wavelet transform coefficients:

WaveletMapIndexed[f,ContinuousWaveletTransform[{0,1,2,0}]]//Normal

OpenersExampleSubsection2(Spacer1)Data  (4)

For list data, the coefficients supplied as the first argument of f are lists:

dwd=DiscreteWaveletTransform[{0,1,2,0}];

Normal[dwd]

Apply a function that transforms lists:

WaveletMapIndexed[c|->2c,dwd]//Normal

For multidimensional data, the coefficients are arrays of the same depth:

dwd=DiscreteWaveletTransform[(({{1, 2, 3, 0}, {5, 6, 0, 8}, {9, 0, 11, 12}, {0, 14, 15, 16}}))];

Normal[dwd]

Apply a function that transforms array coefficients of that depth:

WaveletMapIndexed[c|->Inverse[c],dwd]//Normal

For image data, the coefficients are supplied to f as (RefLink[Image, paclet:ref/Image]) objects:

dwd=DiscreteWaveletTransform[,Automatic,2];

dwd[All,"Image"]

The coefficients have the same number of channels as the original image:

{ImageChannels[{0,2}/.%],ImageChannels[]}

Apply a function that transforms image coefficients:

dwd2=WaveletMapIndexed[c|->Blur[c],dwd]

dwd2[All,"Image"]

For sound data, the coefficients are two-dimensional arrays:

dwd=DiscreteWaveletTransform[Play[{Sin[12000t^2],Sin[16000t^2]},{t,0,0.25}]]

Dimensions of one coefficient:

Dimensions[{0,0,0,1}/.Normal[dwd]]

The two dimensions specify the channel number and the wavelet coefficients for that channel:

Map[ListLinePlot,{0,0,0,1}/.Normal[dwd]]

Apply a function that transforms two-channel data:

f[{l_,r_},index_]:={l,r^2}

dwd2=WaveletMapIndexed[f,dwd]

Map[ListLinePlot,{0,0,0,1}/.Normal[dwd2]]

Reconstructed (RefLink[Sound, paclet:ref/Sound]) data:

InverseWaveletTransform[dwd2]

OpenersExampleSection2(Spacer1)Applications  (7)

OpenersExampleSubsection3(Spacer1)Data Processing  (2)

Coefficients with short indices correspond to small-scale structure in the data:

indspec=index_/;Length[index]≤3;

Zero all small-scale coefficients from the stationary wavelet transform of random data:

WaveletMapIndexed[0#&,StationaryWaveletTransform[RandomReal[1,100]],indspec]

The inverse wavelet transform varies only on larger scales:

ListLinePlot[InverseWaveletTransform[%]]

Perform a simple thresholding operation by removing low-amplitude wavelet coefficients:

d=Sin[(Sqrt[Range[100]])]+RandomReal[0.1,100];

WaveletMapIndexed[Chop[#,0.1]&,StationaryWaveletTransform[d,DaubechiesWavelet[4]]]

Compare with the original data:

{ListLinePlot[d,PlotLabel->"data"],
ListLinePlot[InverseWaveletTransform[%],PlotLabel->"filtered data"]}

OpenersExampleSubsection4(Spacer1)Image Processing  (3)

Blur an image by setting small-scale detail coefficients to zero:

WaveletMapIndexed[ImageMultiply[#,0]&,StationaryWaveletTransform[,Automatic,2],{___,1|2|3}]

Compare with the original image:

{InverseWaveletTransform[%],}

Sharpen an image by amplifying small-scale detail coefficients:

WaveletMapIndexed[ImageMultiply[#,3]&,StationaryWaveletTransform[,Automatic,2],{___,1|2|3}]

Compare with the original image:

{InverseWaveletTransform[%],}

Use a mask image to vary between blurring and sharpening across an image:

WaveletMapIndexed[ImageMultiply[#,]&,StationaryWaveletTransform[,Automatic,3],{___,1|2|3}]

Compare with the original image:

{InverseWaveletTransform[%],}

OpenersExampleSubsection5(Spacer1)Sound Processing  (1)

Apply a nonlinear function to wavelet coefficients for sound data:

dwd=DiscreteWaveletTransform[];

WaveletMapIndexed[c|->Sin[10c^2],dwd]

Inverse transform to obtain a reconstructed sound object:

InverseWaveletTransform[%]

OpenersExampleSubsection6(Spacer1)Wavelet Thresholding  (1)

Perform a wavelet-based shrinkage based on conditional mean:

data=Table[5 Exp[-100 (((t-0.5))^2)]+5 Exp[-10 t],{t,0,1,0.001}];

noisy=data+RandomReal[NormalDistribution[0,0.2],Length[data]];

ListLinePlot[noisy]

Compute a discrete wavelet transform up to refinement level 6:

dwd=DiscreteWaveletTransform[noisy,SymletWavelet[4],6,Padding->"Extrapolated"];

Compute the standard deviation (Subscript[σ, ϵ]) for the finest detail coefficients:

(Subscript[σ, ϵ])=StandardDeviation[First@dwd[{1},"Values"]]

Compute the standard deviation (Subscript[σ, W]) for all wavelet coefficients:

(Subscript[σ, W])=StandardDeviation[Flatten[dwd[{___,1},"Values"]]]

Assuming a Gaussian mixture model, variance (Subscript[σ, G]) can be estimated in the proportion p to 1-p:

p=0.99;

(Subscript[σ, G])=(Sqrt[(((Subscript[σ, W]^2)-(Subscript[σ, ϵ]^2))/(1-p))]);

Shrinkage estimates of the signal coefficients are given by:

b=((Subscript[σ, G]^2)/((Subscript[σ, G]^2)+(Subscript[σ, ϵ]^2)));

c=((p (Sqrt[(Subscript[σ, G]^2)+(Subscript[σ, ϵ]^2)]))/((1-p) (Subscript[σ, ϵ])));

shrink[w_List,wind_]:=((b w)/(1+c Exp[-(((w^2) b)/(2 (Subscript[σ, ϵ]^2)))]))

Use (RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed]) to map over detail coefficients:

ndwd=WaveletMapIndexed[shrink,dwd,{___,1}];

Reconstruct thresholded signal coefficients:

ListLinePlot[{data,InverseWaveletTransform[ndwd]},PlotLabel->"p=0.99"]

OpenersExampleSection3(Spacer1)Properties & Relations  (3)

(RefLink[MapIndexed, paclet:ref/MapIndexed])[f,expr] applies f to the parts of any expression:

MapIndexed[x|->f[x],{a,b,c}]

(RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed])[f,wd] applies f to the coefficients in the wavelet data object wd:

dwd=DiscreteWaveletTransform[{0,1,2}];

WaveletMapIndexed[v|->Rescale[v],dwd]//Normal

(RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed])[v|->Map[f,v],wd] applies f to each part of each coefficient:

WaveletMapIndexed[v|->Map[f,v],dwd]//Normal

(RefLink[MapIndexed, paclet:ref/MapIndexed]) gives the part specification as the second argument of f:

MapIndexed[{x,p}|->f[x,p],{a,b,c}]

(RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed]) gives the wavelet index specification as the second argument of f:

WaveletMapIndexed[{v,wind}|->Map[f[#,wind]&,v],DiscreteWaveletTransform[{0,1,2}]]//Normal

(RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed]) transforms arrays of coefficients, giving a new (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]):

dwd=DiscreteWaveletTransform[Sqrt[Range[10]]];

WaveletMapIndexed[v|->v^2,dwd]

Use (RefLink[Map, paclet:ref/Map]) and (RefLink[Normal, paclet:ref/Normal])[dwd] to transform coefficients into normal expressions:

Map[ListLinePlot[Last[#]]&,Normal[dwd]]

Or use (RefLink[ReplaceAll, paclet:ref/ReplaceAll]) (/.):

Normal[dwd]/.(wind_->v_):>Framed[v]

OpenersExampleSection4(Spacer1)Possible Issues  (2)

The function f is always passed the index specification as its second argument:

dwd=StationaryWaveletTransform[];

WaveletMapIndexed[Blur,dwd]

Use a function that operates on its first argument only:

WaveletMapIndexed[img|->Blur[img],dwd]

The function f should return an array or image of the same dimensions:

dwd=DiscreteWaveletTransform[{0,0,1,0,0}];

WaveletMapIndexed[c|->0,dwd]

(RefLink[Listable, paclet:ref/Listable]) functions return an array of the same dimensions:

WaveletMapIndexed[c|->Sqrt[c],dwd]

Arithmetic operations such as multiplication are (RefLink[Listable, paclet:ref/Listable]):

WaveletMapIndexed[c|->0c,dwd]

Use (RefLink[Map, paclet:ref/Map]) for functions that are not (RefLink[Listable, paclet:ref/Listable]):

WaveletMapIndexed[c|->Map[f,c],dwd]//Normal

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ContinuousWaveletData, paclet:ref/ContinuousWaveletData])  ▪  (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData])  ▪  (RefLink[WaveletThreshold, paclet:ref/WaveletThreshold])  ▪  (RefLink[DiscreteWaveletTransform, paclet:ref/DiscreteWaveletTransform])  ▪  (RefLink[ContinuousWaveletTransform, paclet:ref/ContinuousWaveletTransform])  ▪  (RefLink[InverseWaveletTransform, paclet:ref/InverseWaveletTransform])  ▪  (RefLink[MapIndexed, paclet:ref/MapIndexed])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Wavelet Analysis, paclet:guide/Wavelets])}})}})