clear
N=input('What is the value of N?\n')
%N=11;
A=(N-1)/2;
k=0:1:N-1;
fs=input('What is the sample frequency?\n')
%fs=950;
fco=input('What is the cuton frequency?\n')
%fco=150;
vco=fco/fs; %convert to normalised frequency
wa=1; %width of the ALLPASS filter
wb=2*vco; % width of the lowpass filter
%calculate the filter impulse responses
ha=wa*sinc(wa*(k-A)); %filter A the ALLPASS response
hb=wb*sinc(wb*(k-A)); %filter B the LOWPASS response
h=ha-hb; %the response of the HIGHPASS
% create a sum of two sin waves so that the 
%filter can be tested
t=0:1/950:10; %samples of the sine waves
tone=input('What is the frequency of the first test sine wave?\n')
test1=sin(2*pi*tone*t); %a sine wave of tone Hz 
ttwo=input('What is the frequency of the second test sine wave?\n')
test2=sin(2*pi*ttwo*t); %a sine wave of ttwo Hz 
x=test1+test2; % add the sine waves together
%pass the composite sine wave 'a' thriough the filter h
a=filter(h,1,x); 
%find the spectrum of the composite waveform
[Hx,fx]=freqz(x,1,512,950);
%find the spectrum of the waveform after passing through the filter
[Ha,fa]=freqz(a,1,512,950);
%plot filtered and unfiltered waveforms together
subplot(2,1,1)
plot(fx,abs(Hx))
title('Spectrum of original signal')
subplot(2,1,2)
plot(fa,abs(Ha))
title('Spectrum of filtered signal')

