yading@11: function Y = genspecsines (ploc, pmag, pphase, N) yading@11: % Compute a spectrum from a series of sine values yading@11: % iploc, ipmag, ipphase: sine locations, magnitudes and phases, N: size of complex yading@11: % spectrum; Y: generated complex spectrum of sines yading@11: Y =zeros(N,1); % initialize output spectrum yading@11: hN = N/2+1; % size of positive freq. spectrum yading@11: for i=1:length(ploc); % generate all sine spectral lobes yading@11: loc = ploc(i)-1; % location of peak (zero-based indexing),range ]0,hN-1[ yading@11: if (loc<=1||loc>=hN-1) continue; end; % avoid frequencies out of range yading@11: binremainder = round(loc)-loc; yading@11: lb = [binremainder-4:binremainder+4]'; % main lobe (real value) bins to read yading@11: lmag = genbh92lobe(lb)*10.^(pmag(i)/20); % lobe magnitudes of the complex exponential yading@11: b = 1+[round(loc)-4:round(loc)+4]'; % spectrum bins to fill (1-based indexing) yading@11: for m=1:9 yading@11: if (b(m)<1) % peak lobe crosses DC bin yading@11: Y(2-b(m)) = Y(2-b(m)) + lmag(m)*exp(-1i*pphase(i)); yading@11: elseif (b(m)>hN) % peak lobe croses Nyquist bin yading@11: Y(2*hN-b(m)) = Y(2*hN-b(m)) + lmag(m)*exp(-1i*pphase(i)); yading@11: else % peak lobe in positive freq. range yading@11: Y(b(m)) = Y(b(m)) + lmag(m)*exp(1i*pphase(i)) ... yading@11: + lmag(m)*exp(-1i*pphase(i))*(b(m)==1||b(m)==hN); yading@11: end yading@11: end yading@11: Y(hN+1:end) = conj(Y(hN-1:-1:2)); % fill the rest of the spectrum yading@11: end yading@11: