%REQUIRES trumpet.mat FROM CD
clear;load 'trumpet.mat'
n=5;fc=4000;fs=44100;
L=length(X);dt=1/fs;t=[0:L-1]*dt;
Y=X+0.1*randn(1,L);
%GOAL: Recover X from Y.
%Design Butterworth filter:
D=poly(exp(j*pi*[3:7]'/5));
[R P K]=residue([1],D);
S=2*pi*fc;%Scale factor.
%Butterworth impulse response:
h=real(R.'*exp(P*S*t));
figure,subplot(211),plot(t(1:50),h(1:50))
%Compute frequency response of
%Butterworth filter from h:
Fh=S*fft(h)*dt;%Scale factor.
%Convolve signal and filter
%using Fourier transforms.
FY=fft(Y);Z=real(ifft(FY.*Fh));
%Plot spectrum of FY of Y and
%Frequency response Fh of h.
%See Chapter 8 for details.
%Frequencies for plotting:
FY=2*FY/L;%To plot spectrum of Y.
Iy=[1:3300];fy=(Iy-1)*fs/L;
Ih=[1:8000];fh=(Ih-1)*fs/L;
figure,subplot(211),plot(fy,abs(FY(Iy)))
figure,subplot(211),plot(fh,abs(Fh(Ih)))
%Plot time waveforms of signals:
I=[4601:4900];%Display interval.
figure,subplot(211),plot(t(I),X(I))
figure,subplot(211),plot(t(I),Y(I))
figure,subplot(211),plot(t(I),Z(I))
soundsc(Y,fs),pause,soundsc(Z,fs)
