SpHr_DFTScaleShift [ /Ch /Mag={} /MagS /Phi={} /PhiS ] srcWaveName


Calculates the forward DFT of srcWaveName and then scales magnitude and/or shifts phase before calculating the inverse DFT.


Parameters

srcWaveName  Specification for source wave which is always overwritten. 


Flags

/Ch = [ ch ]    Channel to be shifted or scaled. ch is zero-based (0 or 1). If /Ch is omitted, the first source column is shifted srcWaveName[p][0]


/MAG = { MagScaleWaveName, MagUnits, MagScaleType [ , MagFreqsWaveName ] }

    MagScaleWaveName is a single precision wave of coefficients used to scale magnitude values.

    MagUnits  Magnitude conversion options

      MagUnits = 0, MagScaleWaveName passed values are linear (Pa) (default).

      MagUnits = 1, MagScaleWaveName passed values are in decibels (dB). Passed values are linearized before scaling magnitude (Pa = 10^(dB/20).

    MagScaleType determines what type of coefficients are passed:

     MagScaleType = 0, Each point in MagScaleWaveName is used to scale the real part of the forward DFT. MagScaleWaveName should therefore have half the number of rows as srcWaveName or half of the next largest DFT compatible number of points if dimsize(srcWaveName,0) is not a DFT compatible number.

      MagScaleType = 1, Linear interpolation. MagScaleWaveName values are linearly interpolated before scaling. Coefficient frequencies may be derived from the X-scaling of MagScaleWaveName, specified by a second MagScaleWaveName column, or specified by MagFreqsWaveName. Passed frequencies must increase monotonically. If the first frequency is not 0, a scale value of 1 is appended as the first frequency. If the last frequency is not equal to half the sampling frequency of MagScaleWaveName , a scale of 1 is appended as the last frequency.

      MagScaleType = 2, Cubic spline interpolation. MagScaleWaveName values are interpolated using a cubic spline before scaling. Coefficient frequencies are derived as described above for linear interpolation.

      MagScaleType = 3, Polynomial fit. This method has not been tested for some time and is not recommended. From 2 to 10 polynomial coefficients may be passed starting at index 5. The first point is used to indicate the first frequency above which srcWaveName values are scaled. The second point indicates the last frequency below which srcWaveName values are scaled. Points 2 to 4 are reserved.

      MagScaleType = 4, Quadratic interpolation. MagScaleWaveName values are quadratically interpolated before scaling. Coefficient frequencies may be derived from the X-scaling of MagScaleWaveName, specified by a second MagScaleWaveName column, or specified by MagScaleWaveName. The first passed frequency should be 0. The last frequency should equal half the sampling frequency of MagScaleWaveName.

    MagFreqsWaveName  is a single precision wave of frequencies corresponding to scales passed by MagScaleWaveName.


/MAGS = MagScalesDest

    MagScalesDest name of a wave to which magnitude scale values are written. May be used to verify interpolations.


/PHI = { PhiShiftWaveName, PhiUnits, PhiShiftType [ , PhiFreqsWaveName ] }

    PhiShiftWaveName is a single precision wave of coefficients used to shift phase. Values are assumed to be in radians. Cycles should therefore be converted to radians, e.g., PhiShiftWaveName = PhiShiftWaveName*2*pi.

    PhiUnits  Phase conversion options

      PhiUnits = 0, PhiShiftWaveName passed values are in radians (default).

      PhiUnits = 1, PhiShiftWaveName passed values are in cycles. Passed values are converted to radians before shifting phase (radians = cycles*2π).

      PhiUnits = 2, PhiShiftWaveName passed values are in milliseconds. Passed values are converted to radians before shifting phase (radians = milliseconds*0.001*2*pi*frequency).

    PhiShiftType determines what type of coefficients are passed

      PhiShiftType = 0, Each point in PhiShiftWaveName is used to shift the imaginary part the forward DFT. PhiShiftWaveName should therefore have half the number of rows as srcWaveName or half of the next largest DFT compatible number of points if dimsize(srcWaveName,0) is not a DFT compatible number.

      PhiShiftType = 1, Linear interpolation. PhiShiftWaveName values are linearly interpolated before scaling. Coefficient frequencies may be derived from the X-scaling of PhiShiftWaveName, specified by a second PhiShiftWaveName column, or specified by PhiShiftWaveName. Passed frequencies must increase monotonically. If the first frequency is not 0, a shift value of 0 is appended as the first frequency. If the last frequency is not equal to half the sampling frequency of PhiShiftWaveName , a shift of 0 is appended as the last frequency.

      PhiShiftType = 2, Cubic spline interpolation. PhiShiftWaveName values are interpolated using a cubic spline before scaling. Coefficient frequencies are derived as described above for linear interpolation.

      PhiShiftType = 3, Polynomial fit. This method has not been tested for some time and is not recommended. From 2 to 10 polynomial coefficients may be passed starting at index 5. The first point is used to indicate the first frequency above which srcWaveName values are scaled. The second point indicates the last frequency below which srcWaveName values are scaled. Points 2 to 4 are reserved.

      PhiShiftType = 4, Quadratic interpolation. PhiShiftWaveName values are quadratically interpolated before scaling. Coefficient frequencies may be derived from the X-scaling of PhiShiftWaveName, specified by a second MagScaleWaveName column, or specified by PhiFreqsWaveName. The first passed frequency should be 0. The last frequency should equal half the sampling frequency of PhiShiftWaveName.

    PhiFreqsWaveName   is a single precision wave of frequencies corresponding to shifts passed by PhiShiftWaveName.


/PHIS = PhiShiftsDest

    PhiShiftsDest name of wave to which phase shift values are written. May be used to verify interpolations.


Example

Function SpHr_DFTScaleShift_Example()

    variable fs = 48000

    SpHr_SignalBinaural/ms=1000/Ramp=20/dB=70/Sp=0 fs, Noise

    variable type = 1 // linear interpolation

    // scale values and corresponding frequencies

    Make/O MagScales = {{0, 0, 6, 6, 0, 0},{0, 399, 400, 999, 1000, fs/2}}

    Make/O PhiShifts = {{0, 0, 0.5, 0.5, 0, 0},{0, 399, 400, 999, 1000, fs/2}}

    variable MagUnits = 1 // Magnitudes in dB, converted internally to Pa (= 10^(dB/20))

    variable PhiUnits = 2 // Phase passed in milliseconds, converted internally to radians (= ms*0.001*2*pi*Hz)

    SpHr_DFTScaleShift/Ch=0/Mag={MagScales,MagUnits,type}/MagS=MagInterp /Phi={PhiShifts,PhiUnits,type}/PhiS=PhiInterp Noise

    // Display magnitude spectrum shifts

    SpHr_DFTSpectrum /Mag=Mag/dB /Oct=64 Noise

    Display /K=1/W=(49,100,557,364)/K=1 as "Magnitude spectrum shifts"

    AppendToGraph Mag[][0], Mag[][1] 

    ModifyGraph rgb(Mag)=(0,0,65535), lblMargin=3

    ModifyGraph log(bottom)=1; SetAxis bottom 50,*

    Label left "amplitude (\\U)"; Label bottom "frequency (\\U)"

    AppendToGraph/R MagInterp

    ModifyGraph rgb(MagInterp)=(0,0,0)

    Label right "interpolated mag scales"

    SetAxis/A/N=2 right

    ModifyGraph lsize=0.5,tick=2,fSize=10,axThick=0.5

    ModifyGraph standoff=0,btLen=4,btThick=0.5,stLen=2,stThick=0.5

    TextBox/C/N=text0/F=0/B=1/H={15,0,5}/A=RC/X=10.00/Y=-15.00 "\\s(Mag) left\r\\s(Mag#1) right\r\r\\s(MagInterp) interpolated\rmagnitude scales"

    // Display ILDs and ITDs

    SpHr_FilterCenterFreqs/R/Type=(2)/E=CFedges 100, 5000, 64, CFs // log

    SpHr_FilterBankBiquadCoefs 48000, CFs, coefBank

    SpHr_FilterBankBiquad /RMS/Dest=FilterBanks CFs, coefBank, Noise

    killwaves/Z coefBank, Noise

    SpHr_CrossingCarrierCues/ILD=ILDs/ITD=ITDs/IPD=IPDs CFs, FilterBanks

    SpHr_Histogram /Norm/Sym={-18,201} ILDs, ILDs_Hist

    SpHr_Histogram /Norm/Sym={-0.5,201} IPDs, IPDs_Hist

    SpHr_Histogram /Norm/Sym={-0.001,201} ITDs, ITDs_Hist

    // ILD

    Display /K=1/W=(11,387,300,717)/K=1  as "Scaled DFT - ILD"

    AppendImage ILDs_Hist vs {*,CFedges}

    ModifyImage ILDs_Hist ctab= {*,*,SeaLandAndFire,0}

    ModifyGraph log(left)=1,tick=2

    ModifyGraph zero(bottom)=3,mirror=0,fSize=10,lblMargin=3

    ModifyGraph standoff=0,axThick=0.5,zeroThick(bottom)=0.5

    ModifyGraph btLen=4,btThick=0.5,stLen=2,stThick=0.5

    ModifyGraph manTick(bottom)={0,6,0,0},manMinor(bottom)={0,50}

    Label left "frequency (\\U)"

    Label bottom "interaural level difference (\\U)"

    // ITD

    Display /K=1/W=(303,388,592,718)/K=1 as "Shifted DFT - ITD"

    AppendImage ITDs_Hist vs {*,CFedges}

    ModifyImage ITDs_Hist ctab= {*,*,SeaLandAndFire,0}

    ModifyGraph log(left)=1,tick=2

    ModifyGraph zero(bottom)=3,mirror=0,fSize=10,lblMargin=3

    ModifyGraph standoff=0,axThick=0.5,zeroThick(bottom)=0.5

    ModifyGraph btLen=4,btThick=0.5,stLen=2,stThick=0.5

    Label left "frequency (\\U)"

    Label bottom "interaural time difference (\\U)"

End

Contact: Brian