function slide=rcosdemo
% Demonstration of raised cosine functions
%   
%   RCOSDEMO is a slideshow demonstration that uses the communications toolbox
%   functions, RCOSINE and RCOSFLT, to demonstrate the intersymbol interference
%   rejection capability of the raised cosine filter.  RCOSDEMO demonstrates how
%   to use RCOSINE and RCOSFLT, how the raised cosine filter controls
%   intersymbol interference, and how to split the raised cosine filtering
%   between transmitter and receiver.

%   Copyright 1996-2000 The MathWorks, Inc.
%   $Revision: 1.14 $ $Date: 2000/08/29 19:05:19 $
if nargout<1,
  playshow rcosdemo
else
  %========== Slide 1 ==========

  slide(1).code={
    'fig = gcf;',
    'sp = get(fig,''position'');',
    'ss = get(0,''ScreenSize'');',
    'fp1 = [ss(3)*0.5-sp(3)*0.5  ss(4)*.80-sp(4) sp(3)*1.05 sp(4)*1.1];',
    'if ichange == 0  & size(slideData.param,2) == 1; set(gcf,''position'',fp1); end;',
	'Delay = 3;DataL = 20;R=.5; Fs=8;Fd=1;PropD = 0; % parameters'
	'x = randsrc(DataL, 1, [], 1245);                % generate random data'
	'tx = [PropD: PropD + DataL - 1] ./ Fd;          % at time 0, 1/Fd, 2/Fd, ...'
	'stem(tx, x, ''kx'');                             % plot data'
	'axis([0 30 -1.6 1.6 ]);  xlabel(''Time''); ylabel(''Amplitude'');  % set axes'
	};
  slide(1).text={
    'This demo shows how to design and use raised cosine filters. The data sequence above represents a digital sequence that will be upsampled by zero-padding before filtering.  Raised cosine filters will be used to shape the waveform without introducing intersymbol interference (ISI).',
   '',
	'Delay = 3;DataL = 20;R=.5; Fs=8;Fd=1;PropD = 0;          % Parameters.'
	'x = randsrc(DataL, 1, [], 1245);                                         % Generate random data'
	'tx = [PropD: PropD + DataL - 1] ./ Fd;                              % at time 0, 1/Fd, 2/Fd, ...'
	'stem(tx, x, ''kx'');                                                                  % Plot data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude'');           % Set axes and labels'
   };

  %========== Slide 2 ==========

  slide(2).code={
	'[yf, tf] = rcosine(Fd, Fs, ''fir'', R, Delay);                   % design filter'
	'[yo, to] = rcosflt(x, Fd, Fs, ''filter'', yf);                    % upsample and filter'
	'stem(tx, x, ''kx''); hold on;                                              % plot data'
	'plot(to, yo, ''b-''); hold off;                                            % plot data and filtered data'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % Set axes and labels.'
	};
  slide(2).text={
   'RCOSFLT is used to upsample and filter the data stream using the filter designed by RCOSINE.  The plot compares the digital data and the upsampled, filtered signal. It is difficult to compare the two signals because the peak response of the filter is delayed by the group delay of the filter (order/(2*Fs)).  The next slide compensates for this delay.',
   '',
	'[yf, tf] = rcosine(Fd, Fs, ''fir'', R, Delay);                     % Design filter.'
	'[yo, to] = rcosflt(x, Fd, Fs, ''filter'', yf);                         % Upsample and filter.'
	'stem(tx, x, ''kx''); hold on;                                          % Plot data.'
	'plot(to, yo, ''b-''); hold off;                                          % Plot filtered data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % Set axes and labels.'
   ''};


  %========== Slide 3 ==========

  slide(3).code={
    'PropD = Delay * Fd;                        % correct for propagation delay'
	'tx = [PropD: PropD + DataL - 1] ./ Fd;  % at time 0, 1/Fd, 2/Fd, ...'
	'stem(tx, x, ''kx''); hold on;                         % plot data'
	'plot(to, yo, ''b-''); hold off;                           % plot data and filtered data'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude'');   % Set axes and labels.'
	};
  slide(3).text={
   'This slide compensates for the raised cosine filter group delay by delaying the input signal.   Now it is easy to see how the raised cosine filter upsamples and filters the signal.  The filtered signal is identical to the delayed input signal at the input sample times. This demonstrates the raised cosine filter capability to band-limit the signal while avoiding ISI.',
   '',
    'PropD = Delay * Fd;                                                 % Correct for propagation delay'
	'tx = [PropD: PropD + DataL - 1] ./ Fd;                     % at time 0, 1/Fd, 2/Fd, ...'
	'stem(tx, x, ''kx''); hold on;                                           % Plot data.'
	'plot(to, yo, ''b-''); hold off;                                           % Plot filtered data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % Set axes and labels.'
   ''};

  %========== Slide 4 ==========

  slide(4).code={
	'[yg, tg] = rcosine(Fd, Fs, ''fir'', .2, Delay);   % design filter'
	'[yo1, to1] = rcosflt(x, Fd, Fs, ''normal/fir/filter'',yg);      % design and filter'
	'stem(tx, x, ''kx''); hold on;                         % plot data'
	'plot(to, yo, ''b-'',to1, yo1, ''r-''); hold off;                        % plot data and filtered data'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % set axes'
	};
  slide(4).text={
   'This slide demonstrates the effect that changing the rolloff factor from .5 (blue curve) to .2 (red curve) has on the resulting filtered output.  The lower value for rolloff causes the filter to have a narrower transition band causing the filtered signal overshoot to be greater for the red curve than for the blue curve.',
   '',
	'[yg, tg] = rcosine(Fd, Fs, ''fir'', .2, Delay);                  % Design filter.'
	'[yo1, to1] = rcosflt(x, Fd, Fs, ''normal/fir/filter'',yg);    % Filter data.'
	'stem(tx, x, ''kx''); hold on;                                          % Plot data.'
	'plot(to, yo, ''b-'',to1, yo1, ''r-''); hold off;                       % Plot filtered data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % Set axes and labels.'
   ''};

  %========== Slide 5 ==========

  slide(5).code={
	'[ys, ts] = rcosine(Fd, Fs, ''fir/sqrt'', R, Delay);   % Design square root filter.'
	'[yc, tc] = rcosflt(x, Fd, Fs, ''filter'', ys);          % Filter at the transmitter.'
	'stem(tx, x, ''kx''); hold on;                               % Plot data.'
	'plot(tc, yc, ''m-''); hold off;                           % Plot filtered data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % Set axes and labels.'
	};
  slide(5).text={
   'A typical use of raised cosine filtering is to split the filtering between transmitter and receiver.  The data stream is upsampled and filtered at the transmitter using the square-root raised cosine filter.   The plot above shows the transmitted signal when filtered using the square-root raised cosine filter. The "fir/sqrt" switch was used with RCOSINE to generate the square-root raised cosine filter.',
   '',
	'[ys, ts] = rcosine(Fd, Fs, ''fir/sqrt'', R, Delay);            % Design square root filter.'
	'[yc, tc] = rcosflt(x, Fd, Fs, ''filter'', ys);                        % Filter at the transmitter.'
	'stem(tx, x, ''kx''); hold on;                                          % Plot data.'
	'plot(tc, yc, ''m-''); hold off;                                         % Plot filtered data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % Set axes and labels.'
   ''};


  %========== Slide 6 ==========

  slide(6).code={
	'[yr, tr] = rcosflt(yc, Fd, Fs, ''filter/Fs'', ys);              % filter at the transmitter'
	'tcc = tc + Delay .* Fd;  txx = tx + Delay .* Fd;        % adjust for propagation delay'
	'stem(txx, x, ''kx''); hold on;                         % plot data'
	'plot(tcc, yc, ''m-'',tr, yr, ''b-''); hold off;    % plot data and filtered data'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % set axes'
	};
  slide(6).text={
      'The transmitted signal (magenta curve) is then filtered, but not upsampled, at the receiver, using the same square-root raised cosine filter, resulting in a signal depicted by the blue curve at the receiver. The resulting signal is virtually identical to the signal filtered using a single raised cosine filter.  The "Fs" was used to filter without upsampling.',
   ''
	'[yr, tr] = rcosflt(yc, Fd, Fs, ''filter/Fs'', ys);                   % Filter at the receiver.'
	'tcc = tc + Delay .* Fd;  txx = tx + Delay .* Fd;          % Adjust for propagation delay.'
	'stem(txx, x, ''kx''); hold on;                                         % Plot data.'
	'plot(tcc, yc, ''m-'',tr, yr, ''b-''); hold off;                          % Plot filtered data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % Set axes and labels.'
   };

  %========== Slide 7 ==========

  slide(7).code={
	'[yo2, to2] = rcosflt(x, Fd, Fs, ''normal/fir'', R, Delay);     % Design and filter.'
	'stem(tx, x, ''kx''); hold on;                                          % Plot data.'
	'plot(to2, yo2, ''b-''); hold off;                                          % Plot filtered data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude''); % Set axes and labels.'
	};
  slide(7).text={
   'This slide demonstrates a quicker way to filter data using RCOSFLT.  When RCOSFLT is used without the "filter" type switch, it designs a filter and uses it to filter the input data.  This slide creates the same plot as slide 3 but designs the raised cosine filter and generates the filtered stream in one command.',
   '',
	'[yo2, to2] = rcosflt(x, Fd, Fs, ''normal/fir'', R, Delay);     % Design and filter.'
	'stem(tx, x, ''kx''); hold on;                                              % Plot data.'
	'plot(to2, yo2, ''b-''); hold off;                                          % Plot filtered data.'
	'axis([0 30 -1.6 1.6]);  xlabel(''Time''); ylabel(''Amplitude'');     % Set axes and labels.'
   ''};

end