% compute the different harmonics that can be obtained by beats
% between different lines (for example RF modulations)
format compact
format shortg

% list of modulation frequencies
freq = [6270783 8361045 56436993 ...
        4006184.1 5529427.0 8245000.0 11120000.0 ...
        ];
nFreq = length(freq);

% up to which order explore combinations
nOrder = 3; % order of a RF harmonic
maxTotOrder = 8; % total order of combination
orderList = -nOrder:nOrder;

% up to which frequency to display
maxFreq = 20e3;

% make combination integer
possibleCombination = combvec(orderList, orderList, orderList, ...
                              orderList, orderList, orderList, ...
                              orderList);

% compute combination frequencies
maskTotOrder = sum(abs(possibleCombination)) <= maxTotOrder;
lowOrderCombination = possibleCombination(:, maskTotOrder);
possibleFreq = freq*lowOrderCombination;

% find unique frequency combination
[uniqueFreqAbs I] = unique(abs(possibleFreq));

% show combination up to maxFreq
maskShowFreq = uniqueFreqAbs < maxFreq;

combinationFrequency = uniqueFreqAbs(maskShowFreq)
combinationCoefficients = lowOrderCombination(:,I(maskShowFreq))
combinationOrder = sum(abs(combinationCoefficients))
