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