annotate genspecsines.m @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 function Y = genspecsines (ploc, pmag, pphase, N)
yading@11 2 % Compute a spectrum from a series of sine values
yading@11 3 % iploc, ipmag, ipphase: sine locations, magnitudes and phases, N: size of complex
yading@11 4 % spectrum; Y: generated complex spectrum of sines
yading@11 5 Y =zeros(N,1); % initialize output spectrum
yading@11 6 hN = N/2+1; % size of positive freq. spectrum
yading@11 7 for i=1:length(ploc); % generate all sine spectral lobes
yading@11 8 loc = ploc(i)-1; % location of peak (zero-based indexing),range ]0,hN-1[
yading@11 9 if (loc<=1||loc>=hN-1) continue; end; % avoid frequencies out of range
yading@11 10 binremainder = round(loc)-loc;
yading@11 11 lb = [binremainder-4:binremainder+4]'; % main lobe (real value) bins to read
yading@11 12 lmag = genbh92lobe(lb)*10.^(pmag(i)/20); % lobe magnitudes of the complex exponential
yading@11 13 b = 1+[round(loc)-4:round(loc)+4]'; % spectrum bins to fill (1-based indexing)
yading@11 14 for m=1:9
yading@11 15 if (b(m)<1) % peak lobe crosses DC bin
yading@11 16 Y(2-b(m)) = Y(2-b(m)) + lmag(m)*exp(-1i*pphase(i));
yading@11 17 elseif (b(m)>hN) % peak lobe croses Nyquist bin
yading@11 18 Y(2*hN-b(m)) = Y(2*hN-b(m)) + lmag(m)*exp(-1i*pphase(i));
yading@11 19 else % peak lobe in positive freq. range
yading@11 20 Y(b(m)) = Y(b(m)) + lmag(m)*exp(1i*pphase(i)) ...
yading@11 21 + lmag(m)*exp(-1i*pphase(i))*(b(m)==1||b(m)==hN);
yading@11 22 end
yading@11 23 end
yading@11 24 Y(hN+1:end) = conj(Y(hN-1:-1:2)); % fill the rest of the spectrum
yading@11 25 end
yading@11 26