%Example 8-19: Noise filtering trumpet.
clear;load trumpet.mat
NS=0.1;T=0.0015;fs=44100;
L=length(X);rand('seed',0);
N=NS*randn(1,L);Y=X+N;%noisy
FY=fft(Y)/L;FZ=FY;
FZ(find(abs(FY)<T))=0;
Z=L*real(ifft(FZ));
SNR=10*log10(sum(X.^2)/sum(N.^2))
%Plot time waveforms and spectra:
NN=[1000:1199];t=NN/fs;%display
FF=[1:5000];f=(FF-1)*fs/L;%display
subplot(211),plot(t,Y(NN)),axis tight
subplot(212),plot(t,Z(NN)),axis tight
figure
subplot(211),plot(f,abs(FY(FF))),axis tight
subplot(212),plot(f,abs(FZ(FF))),axis tight
soundsc(Y,fs),pause,soundsc(Z,fs)