function demoPAMsrrc(a,M,beta,syms)
% This function demonstrates the generation
% of a PAM signal from the symbol amplitudes
% in the vector a, using an upsampling factor
% of M.
% example run demoPAMsrrc([3 3 -1 1 -3 1],100,0.5,2)
aup=upsample(a,M); % Upsampled Data Symbol Sequence
%g=hamming(M,'symmetric')';
%g=hanning(M,'symmetric')'; % Transmit Pulse
g=srrc(syms,beta,M); % Use SRRC pulse
scale=sqrt(sum(g.*g));
g=g/scale; % Normalize to unit energy
A=max(g);
h=[0 fliplr(g)]; % Matched Filter h(n) = g(M-n)
s=conv(g,h); % Zero ISI Pulse
offset = length(s)/2
x=conv(g,aup); % Filter Data to Form Transmitted Signal
x1=filter(h,1,aup); % Alternative filtering command
y=conv(h,x); % Apply Matched Filter
y1=filter(fliplr(g)/(pow(g)*M),1,x1); % Alternative MF
figure(1) % Plot g(n), h(n) and s(n)
subplot(2,1,1)
plot([0:length(g)-1],g,[0:length(h)-1],h,'--')
xlabel('Time Index, n')
ylabel('g(n), h(n)')
title('Transmit and Receive Filter Impulse Responses')
legend('Transmit Filter, g(n)','Receive Filter, h(n)')
subplot(2,1,2)
plot(s)
xlabel('Time Index, n')
ylabel('s(n) = g(n)*h(n)')
title('Zero ISI Pulse')
figure(2) % Plot data symbols, transmit signal, and MF output
subplot(2,1,1)
stem([0:M*length(a)-1],[aup zeros(1,M*length(a)-length(aup))],'.')
xlabel('Time Index, n')
ylabel('a_{up}(n)')
title('Input Symbol Sequence')
subplot(2,1,2)
plot([0:length(x)-1],scale*x/A,'--',[0:length(y)-1],y) %,[0:length(y1)-1],y1)
xlabel('Time Index, n')
ylabel('x(n), y(n)')
title('Transmitted Signal and Matched Filter Output')
legend('Trans. Signal, x(n)','MF Output, y(n)')
hold on
stem([0:length(a)-1]*M+1+offset,y(1+offset:M:1+offset+M*(length(a)-1)),'.')
hold off

    