% example of digital filtering with highpass filter

w1 = 400*2*pi;
fs = 10000;
w2 = 4000*2*pi;
t = 0:1/fs:2;
x = 0.5*cos(w1*t)+0.5*cos(w2*t);
sound(x,fs)

% design of Chebyshev Type 1 highpass filter with wc = 1000 hz
N = 2;    % number of poles
Rp = 3;   % passband ripple
T = .2;   % sampling period
wc = 2;   % analog cutoff frequency
Omegac = wc*T/pi;    % normalized digital cutoff frequency
[numd,dend] = cheby1(N,Rp,Omegac,'high');
disp('Digital filter:')
numd = real(numd) % strips off negligible imag part introduced in roundoff
dend = real(dend)

% filter the signal and display the results
y = filter(numd,dend,x);  % filters x
figure(1)
subplot(211), plot(t(1:200),x(1:200))
ylabel('x(t)')
title('Highpass filter')
xlabel('Time (sec)')
subplot(212),plot(t(1:200),y(1:200))
xlabel('Time (sec)')
ylabel('y(t)')
Omega = -pi:pi/200:pi;
H = freqz(numd,dend,Omega);
figure(2)
subplot(211),plot(Omega,abs(H))
axis([-pi pi 0 1])
title('Frequency Response')
ylabel('|H|')
xlabel('\Omega')
hold on
H12 = freqz(numd,dend,[w1/fs w2/fs]);
plot([w1/fs w2/fs],abs(H12),'ro')
hold off

% create wave files 
wavwrite(x,fs,'d:\web_pages\book\applets\chap11\x')
wavwrite(y,fs,'d:\web_pages\book\applets\chap11\yhp')
pause
sound(y,fs)





