** Script to initialise and read "Define Fourier Dialog" box ** ** Supported versions: 5.1-5.1a ** ** Modified for y-axis in dB Let newGraph = 1 Let probe = 0 Let yExpr = '' Let signalName = '' ** arg is a string array that is passed to DefineFourierDialog to initialise it ** The format is an extension of that used for DefineCurveDialog let arg=MakeString(37) let arg[0]='auto' ;** axistype ** If there is a graph open, axes are initialised according to currently ** selected axis if SelGraph() then if newGraph || GetAxisUnits(GetXAxis())<>'Hertz' then let arg[1]='newsheet' let arg[10]='lin' ;** xlog log|lin|auto let arg[11]='auto' ;** x noChange|auto|defined let arg[12]='lin' ;** ylog let arg[13]='auto' ;** x noChange|auto|defined let arg[14]='0' ;** xmin let arg[15]='1' ;** xmax let arg[16]='0' ;** ymin let arg[17]='1' ;** ymax else let arg[1]='add' ** Get axis info let xId = GetXAxis() let yId = GetSelectedYAxis() let xLimits = GetAxisLimits(xId) let yLimits = GetAxisLimits(yId) let arg[14] = Str(xLimits[0]) ;** xmin let arg[15] = Str(xLimits[1]) ;** xmax if xLimits[2]=0 then let arg[10] = 'lin' else let arg[10] = 'log' endif if xLimits[3]=0 then let arg[11] = 'noChange' else let arg[11] = 'auto' endif let arg[16] = Str(yLimits[0]) ;** ymin let arg[17] = Str(yLimits[1]) ;** ymay if yLimits[2]=0 then let arg[12] = 'lin' else let arg[12] = 'log' endif if yLimits[3]=0 then let arg[13] = 'noChange' else let arg[13] = 'auto' endif endif else ** Default values when no current graphs open let arg[1]='newwindow' let arg[10]='lin' ;** xlog log|lin|auto let arg[11]='auto' ;** x noChange|auto|defined let arg[12]='lin' ;** ylog let arg[13]='auto' ;** x noChange|auto|defined let arg[14]='0' ;** xmin let arg[15]='1' ;** xmax let arg[16]='0' ;** ymin let arg[17]='1' ;** ymax endif ** Remaining elements let arg[2]='' ;** axisname (probe) let arg[3]='' ;** persistence (probe) let arg[4]='' ;** graphname (probe) if signalName<>'' then let arg[5]='Spectrum('&signalName&')' ;** curve label endif let arg[18]='' ;** xlabel let arg[19]='' ;** xunits let arg[20]='' ;** ylabel let arg[21]='dB' ;** yunits let arg[22]=yExpr ;** expression let arg[23]='' ;** xexpression Let schemPropNames = ['xlog', 'dcdFilter', 'fundamental', 'minFreq', 'maxFreq', 'interpPoints', 'interpOrder', 'method', 'window', 'dataStart', 'dataEnd', 'specSpan', 'knowFund', 'interval'] Let defaults = ['lin', 'top', '', '0', '', '4096', '2', '', 'hanning', '', '', 'false', 'false', ''] Let argIndex = [10, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36] Let numProps = length(schemPropNames) for idx=0 to numProps-1 Let prop = ReadSchemProp(schemPropNames[idx]) if length(prop)<>0 then Let arg[val(argIndex[idx])] = prop else Let arg[val(argIndex[idx])] = defaults[idx] endif next idx if arg[30]='' then Let arg[30] = 'interpolated' endif if 0 then ** Work out number of points in data ** If its greater than 10000 we should default to FFT if ExistVec(yExpr) then let numPoints = length(Val(yexpr)) elseif ExistVec(':time') then let numPoints = length(:time) else Let numPoints = 0 endif if arg[30]='' && numPoints>10000 then Let arg[30] = 'interpolated' endif endif ** 15.12.04 - find a suitable transient run if there is one Let currentGroup = (Groups())[0] select_transient Let newGroup = (Groups())[0] if newGroup<>currentGroup then Echo "Note: Using transient data from data group" {newGroup} "for Fourier plot" endif ** Now call the dialog box if ExistVec(':time') then if !probe then let arg = DefineFourierDialog(arg, :time) else let arg = FourierOptionsDialog(arg, :time) endif else if !probe then let arg = DefineFourierDialog(arg) else let arg = FourierOptionsDialog(arg) endif endif let numArgs = Length(arg) ** Cancelled if numArgs=0 then Exit Script endif if arg[22]='' then Echo "No curve expression specified" Exit Script endif Let exprs = Parse( arg[22], "';'") Let numExprs = Length(exprs) if numExprs>1 then Echo "Only one expression may be entered for fourier analysis" exit script endif Let fundamental = Val(arg[25]) Let minFrequency = Val(arg[26]) Let maxFrequency = Val(arg[27]) Let numPoints = Val(arg[28]) Let order = Val(arg[29]) Let method = arg[30] Let window = arg[31] Let dataStart = Val(arg[32]) Let dataEnd = Val(arg[33]) Let interval = Val(arg[36]) Let plotPhase = iff(arg[37]=='phase',1,0) if probe && plotPhase then Let arg[12] = 'lin' endif if arg[12]='auto' then Let arg[12] = iff(plotPhase, 'lin', 'log') endif if arg[21]='' && plotPhase then Let arg[21]='degrees' endif Let span = Floor( fundamental *(dataEnd - dataStart)+1e-6)/fundamental if span<=0 then Echo "Time span from" {dataStart} "to" {dataEnd} "is in sufficient for fundamental of" {fundamental} exit script endif Let sDataEndMinusSpan = FormatNumber(dataEnd-span,15,'noeng') Let sDataEnd = FormatNumber(dataEnd,15,'noeng') Let expr = 'Truncate('&arg[22]&',' &sDataEndMinusSpan &',' & sDataEnd & ')' if method='interpolated' then Let sMinF = FormatNumber(minFrequency, 15, 'noeng') Let sMaxF = FormatNumber(maxFrequency, 15, 'noeng') Let expr = 'Interp('&expr&',' & numPoints & ',' & order & ')' if window<>'rectangular' then Let sSpan = FormatNumber(span,20,'noeng') Let expr = 'FourierWindow('&expr&',''' & window & ''',' & sSpan & ')' endif if plotPhase=0 then Let fourier = 'db(Truncate(mag(FFT('&expr&', ''none'')),' & sMinF & ',' & sMaxF & '))' else Let fourier = 'Truncate(phase(FFT('&expr&', ''none'')),' & sMinF & ',' & sMaxF & ')' endif elseif method='continuous' then if window<>'rectangular' then Let expr = 'FourierWindow('&expr&',''' & window & ''')' endif Let numTerms = Floor((maxFrequency-minFrequency)/interval)+1 Let startTerm = Floor(minFrequency/interval) Let sInterval = FormatNumber(interval,15,'noeng') if plotPhase=0 then Let fourier = 'db(Fourier('&expr&',' & sInterval & ',' & numTerms & ',' & startTerm & '))' else Let fourier = 'Phase(Fourier('&expr&',' & sInterval & ',' & numTerms & ',' & startTerm & '))' endif else Echo "Internal error" in {ScriptName()} " script. Unrecognised Fourier method" exit script endif **exit script if arg[5]='' then Let arg[5] = 'Spectrum(' & arg[22] & ')' endif let switches = MakeString(20) let addCurve= arg[1]=='add' Let numSwitches=0 for idx=0 to numProps-1 Let WriteSchemProp(schemPropNames[idx], arg[val(argIndex[idx])], 'create') next idx compile_graph_switches arg addCurve @switches @numSwitches ** Bug fix SX00248B if arg[23]<>'' then Let arg[22] = arg[22] & ',' endif if numSwitches=0 then ** No switches if addCurve then Curve /coll {fourier} else Plot /coll {fourier} endif exit script endif let swt = MakeString(numSwitches) for j=0 to numSwitches-1 let swt[j] = switches[j] next j if ExistVec('$var1') && ExistVec('$var2') && ExistVec('$var3') && ExistVec('$var4') then Let $var1 = swt Let $var2 = arg[22] Let $var3 = arg[23] Let $var4 = addCurve elseif addCurve then curve /coll {swt} {fourier} else plot /coll {swt} {fourier} endif if newGroup<>currentGroup then SetGroup {currentGroup} endif