%This shows how the 1-D DFT can be used to eliminate one of
%two trumpet signals playing notes A and B from their sum.
%REQUIRES THE .mat FILE twotrumpets.mat
clear;load twotrumpets.mat;
S=44100;N=length(X);F=[0:4999]*S/N;NN=[1000:1199];T=NN/S;%Hz and waveform time display.
figure,plot(T,X(NN)),axis([T(1) T(200) -0.7 0.9]),title('Waveform of two-trumpet signal')
FX=fft(X);figure,plot(F,abs(FX(1:5000))/N),title('Spectrum of two-trumpet signal')
%Set to zero harmonics of trumpet playing note A:
Z=[301:350 601:700 951:1000 1251:1350 1601:1651 1901:2000 2250:2300 2501:2600 2851:2950];
FX([Z N+2-Z])=0;%Set to zero conjugate frequencies:
figure,plot(F,abs(FX(1:5000)/N)),title('Spectrum of filtered two-trumpet signal')
Y=real(ifft(FX));figure,plot(T,Y(NN)),axis([T(1) T(200) -0.7 0.9]),...
title('Waveform of filtered two-trumpet signal')
soundsc(X,S),pause,soundsc(Y,S)%Sounds of two trumpets and filtered two trumpets.
