%Example 8-20: Two trumpets, revisited.
%Separating two trumpet signals by setting the
%DFT-computed harmonics of one trumpet to 0.
clear;load twotrumpets.mat;
fs=44100;f=440;%reject note A
L=length(X);FX=fft(X)/L;FY=FX;
NF=round(f*L/fs);%fundamental index
%K=indices where spectra set to 0:
K=[];for I=1:9;
K=[K ([-30:30]+I*NF)];end
K=[K L+2-K];%append conjugate indices
FY(K)=0;%set harmonics of f to 0.
Y=L*real(ifft(FY));
%Plot time waveforms and spectra:
NN=[1000:1199];t=NN/fs;%display
FF=[1:5000];f=(FF-1)*fs/L;%display
subplot(211),plot(f,abs(FX(FF)))
subplot(212),plot(f,abs(FY(FF)))
figure
subplot(211),plot(t,X(NN)),axis tight
subplot(212),plot(t,Y(NN)),axis tight
soundsc(X,fs),pause,soundsc(Y,fs)
