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