function X = genspecsines(iploc,ipmag,ipphase,M,N,bh92lobe) %=> compute the spectrum from a series of sine values % iploc, ipmag, ipphase: location (bin), magnitude (dB) and phase of sinusoids % M size of analysis window % N size of complex spectrum % bh92lobe: spectral main-lobe of a Blackman-Harris window zp = N/M; % zero padding used in the analysis sizelobe=8*zp; halflobe=floor(sizelobe/2)-1; % sample in the middle of the lobe nSines = length(iploc); peakmag=10.^(ipmag/20); % linear magnitude sinphase=sin(ipphase); cosphase=cos(ipphase); X =zeros(N,1); % output spectrum for i=1:nSines if (iploc(i)>halflobe && iploc(i)<=(N/2-halflobe)) firstbin=floor(iploc(i)+1-sizelobe/2); firstbin2=floor(N-iploc(i)+3-sizelobe/2); firstlobeindex = floor(0.5+(1-(iploc(i)-floor(iploc(i))))*512/zp)+1; % first index into lobe bh92i = floor((firstlobeindex:512/zp:4096)); magsin=bh92lobe(bh92i).*sinphase(i)*peakmag(i); magcos=bh92lobe(bh92i).*cosphase(i)*peakmag(i); %--- fill positive frequency if(firstbin>0) X(firstbin:firstbin+length(magcos)-1)= ... X(firstbin:firstbin+length(magcos)-1)+(magcos+j*magsin); end %--- fill negative frequency if (firstbin2 <= (N-(sizelobe-1))) X(firstbin2:firstbin2+length(magcos)-1)= ... fliplr(X(firstbin2:firstbin2+length(magcos)-1)+(magcos-j*magsin)); end end end