Programmer Guide/Command Reference/EVAL/hcomb: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
This function implements a methods to detect harmonics in a spectrum and to create a harmonic comb filter. It was especially implemented for the [[Programmer_Guide/BScript#MulAc|script application '''MulAc''']].
This function implements a methods to detect harmonics in a spectrum and to create a harmonic comb filter.
 
;Usage:<code>hcomb(<var>mflag</var>, <var>oflag</var>, <var>a</var>, <var>imin</var>, <var>imax</var>, <var>ot</var>, <var>ok</var>, <var>oo</var>, <var>nget</var>, <var>rrms</var>, <var>nrms</var>, <var>nset</var>)</code>
;Usage:<code>hcomb(<var>mflag</var>, <var>oflag</var>, <var>a</var>, <var>imin</var>, <var>imax</var>, <var>ot</var>, <var>ok</var>, <var>oo</var>, <var>nget</var>, <var>rrms</var>, <var>nrms</var>, <var>nset</var>)</code>
:;<var>mflag</var>:selects the method used to detect the test tone ''ft''
:;<var>mflag</var>:selects the method used to detect the test tone ''ft''
Line 10: Line 9:
|}
|}
:;<var>oflag</var>:selects the format and content of the result (see '''Result'''); the values '''0''' and '''1''' are supported
:;<var>oflag</var>:selects the format and content of the result (see '''Result'''); the values '''0''' and '''1''' are supported
:;<var>a</var>:a vector containing amplitude spectrum (linear, with constant df); in the description below ''n'' is the length of ''a''.
:;<var>a</var>:a vector containing an amplitude spectrum (linear, with constant df); in the description below ''n'' is the length of ''a''.
:;<var>imin, imax</var>:index range for test tone (''ft'') detection; 0 <= ''imin'' < ''imax'' < ''n''
:;<var>imin, imax</var>:index range for test tone (''ft'') detection; 0 &le; ''imin'' < ''imax'' < ''n''
:;<var>ot</var>:test tone order (''f0'' = ''ft'' / ''ot''); 0 < ''ot''
:;<var>ot</var>:test tone order (''f0'' = ''ft'' / ''ot''); 0 < ''ot''
:;<var>ok, oo</var>:order factor and offset for the components of the comp ''fc''[i];
:;<var>ok, oo</var>:order factor and offset for the components of the comp ''fc''[i];
::<code>''fc''[i] = ''f0'' * (''oo'' + ''ok''*i); with: i=1,2,...</code>
::<code>''fc''[i] = ''f0'' * (''oo'' + ''ok''*i); with: i=1,2,...</code>
:;<var>nget</var>:the number of points (+/-) to detect the peak of a harmonic component ''fc''[i]; 3 <= ''nget''
:;<var>nget</var>:the number of points (+/-) to detect the peak of a harmonic component ''fc''[i]; 3 &le; ''nget''
:;<var>rrms</var>:defines the energy ratio threshold for harmonic components; 0 <= ''rrms'' < 1
:;<var>rrms</var>:defines the energy ratio threshold for harmonic components; 0 &le; ''rrms'' < 1
:;<var>nrms</var>:defines the bandwidth (+/- ''nrms'' points) used to compute the energy ratio; 2 <= ''nrms''
:;<var>nrms</var>:defines the bandwidth (+/- ''nrms'' points) used to compute the energy ratio; 2 &le; ''nrms''
:::(<code>component-rms / testband-rms >= ''rrms''</code>)
:::(<code>component-rms / testband-rms &ge; ''rrms''</code>)
:;<var>nset</var>:defines the comb bandwidth (+/- ''nset'' points); if ''nset'' equals 0, a variable comb bandwidth is used to remove the detected components; this argument is only used if ''oflag'' equals '''1'''
:;<var>nset</var>:defines the comb bandwidth (+/- ''nset'' points); if ''nset'' equals 0, a variable comb bandwidth is used to remove the detected components; this argument is only used if ''oflag'' equals '''1'''
:;
;Description:
#The function extracts the frequency ''ft'' of the test tone from the selected test frequency band (arguments: ''mflag'', ''imin'', ''imax'' and ''rr'').
 
#The argument ''ot'' is used to compute the fundamental frequency ''f0'' of the harmonic comb.
 
#For each frequency band of the harmonic comb is tested if there is a spectral component (peak) or not. The frequency, amplitude and order of the detected harmonic components are saved.
test tone order (''f0'' = ''ft'' / ''ot''); 0 < ''ot''
;Result:  
 
:*''oflag''=0: The result ''r'' is a (M+1)x3 matrix, with M is the number of detected harmonics
 
::{|class ="einrahmen"
 
|''r''[0,0] || fundamental frequency ''f0'' (weighted average of component frequencies)
 
|-
:::<code>mflag(''a'')>2, nrow(''b'')>2, ncol(''a'') = ncol(''b'')</code>
|''r''[0,1], ''r[0,2] || always '''0'''
::Each row of ''a''/''b'' defines one parameter value or vector (e.g. for a frame).
|-
;Result:A matrix Nx2 defining the map of the row indices of ''a'' and ''b'' with the minimum accumulated distance. The first column contains the indices for ''a'' and the second column the indices for ''b''.
|''r''[i,0] || frequency of component i (i=1..M)
:Note:To minimize the distance, individual rows of ''a'' or ''b'' are duplicated. Therefore the number of rows of the result matrix N is greater than or equal to <code>max(nrow(''a''),nrow(''b''))</code>.
|-
----
|''r''[i,1] || amplitude of component i (i=1..M)
;Usage 2:<code>mapmind(1, <var>m</var>, <var>x</var>)</code>
|-
:;<var>m</var>:A vector containing the index map for ''x'';
|''r''[i,2] || order of component i (i=1..M)
:;<var>x</var>:A vector or matrix containing the parameter set to remap.
|}
;Result 2:A vector or matrix ''r'' containing the remapped parameter set ''x''. The number of rows of ''r'' is equal to <code>nrow(''m'')</code> and the number of columns equals <code>ncol(''x'')</code>. The content of the output row <code>''r''[i,*]</code> is a copy of the input row <code>''x''[''m''[i],*]</code>.
:*''oflag''=1: The result ''r'' is a vector with ''n'' elements containing the amplitude spectrum of the comb filter. Inside each detected band the amplitudes are set to '''1''', outside the amplitudes are set to '''0'''.
----
:Note: All frequencies computed and returned by this function are relative frequencies, computed for a frequency resolution ''df''=1.
;See also: [[../dist|dist]]
;See also: [[../optmm|optmm]], [[../cvphase|cvphase]], [[Programmer_Guide/BScript#MulAc|script application '''MulAc''']]
 
 
Example:
<pre>
// macro "alignAB": nonlinear time alignment of two signals,
//                  using the rms track as alignment parameter
// input:  #rmsA, #rmsB ... rms tracks of signal A and B
// result: #aMat .......... alignment matrix, #aMat[*,0] = index vector for signal A
//                                            #aMat[*,1] = index vector for signal B
//                                            #aMat[*,2] = aligned rms track of signal A
//                                            #aMat[*,3] = aligned rms track of signal B
 
[macro alignAB arg: #rmsA #rmsB]
// compute index map with minimum accumulated distance
#map := eval mapmind(0,$#rmsA,$#rmsB)
// remap rms track of signal A
if $rc == 0 #rmsAA := eval mapmind(1, $#map[*,0], $#rmsA)
// remap rms track of signal B
if $rc == 0 #rmsBB := eval mapmind(1, $#map[*,1], $#rmsB)
// create and return the result matrix
if $rc == 0 exit 1 eval vmcol($#map[*,0], $#map[*,1], $#rmsAA, $#rmsBB)
// this point is reached if one of the above commands fails -> error -> return empty string
exit 1 set ''
</pre>


[[../#Functions|<function list>]]
[[../#Functions|<function list>]]

Latest revision as of 19:21, 21 April 2011

This function implements a methods to detect harmonics in a spectrum and to create a harmonic comb filter.

Usage
hcomb(mflag, oflag, a, imin, imax, ot, ok, oo, nget, rrms, nrms, nset)
mflag
selects the method used to detect the test tone ft
mflag=0 peak picking
mflag=1 harmonic grid
oflag
selects the format and content of the result (see Result); the values 0 and 1 are supported
a
a vector containing an amplitude spectrum (linear, with constant df); in the description below n is the length of a.
imin, imax
index range for test tone (ft) detection; 0 ≤ imin < imax < n
ot
test tone order (f0 = ft / ot); 0 < ot
ok, oo
order factor and offset for the components of the comp fc[i];
fc[i] = f0 * (oo + ok*i); with: i=1,2,...
nget
the number of points (+/-) to detect the peak of a harmonic component fc[i]; 3 ≤ nget
rrms
defines the energy ratio threshold for harmonic components; 0 ≤ rrms < 1
nrms
defines the bandwidth (+/- nrms points) used to compute the energy ratio; 2 ≤ nrms
(component-rms / testband-rms ≥ rrms)
nset
defines the comb bandwidth (+/- nset points); if nset equals 0, a variable comb bandwidth is used to remove the detected components; this argument is only used if oflag equals 1
Description
  1. The function extracts the frequency ft of the test tone from the selected test frequency band (arguments: mflag, imin, imax and rr).
  2. The argument ot is used to compute the fundamental frequency f0 of the harmonic comb.
  3. For each frequency band of the harmonic comb is tested if there is a spectral component (peak) or not. The frequency, amplitude and order of the detected harmonic components are saved.
Result
  • oflag=0: The result r is a (M+1)x3 matrix, with M is the number of detected harmonics
r[0,0] fundamental frequency f0 (weighted average of component frequencies)
r[0,1], r[0,2] always 0
r[i,0] frequency of component i (i=1..M)
r[i,1] amplitude of component i (i=1..M)
r[i,2] order of component i (i=1..M)
  • oflag=1: The result r is a vector with n elements containing the amplitude spectrum of the comb filter. Inside each detected band the amplitudes are set to 1, outside the amplitudes are set to 0.
Note: All frequencies computed and returned by this function are relative frequencies, computed for a frequency resolution df=1.
See also
optmm, cvphase, script application MulAc

<function list>

Navigation menu

Personal tools