%% Upconvert Sine Wave Signal
% Create a DUC System object™ that upsamples a 1-kHz sinusoidal signal by a factor of 20 and upconverts it to 50 kHz.
% Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).
% Create a sine wave generator to obtain the 1-kHz sinusoidal signal with a sample rate of 6 kHz.

 Fs = 6e3; % Sample rate
 sine = dsp.SineWave('Frequency',1000,'SampleRate',Fs,'SamplesPerFrame',1024);
 x = sine(); % generate signal

%
% Create a DUC System object. Use minimum order filter designs and set the passband ripple to 0.2 dB and stopband attenuation to 55 dB. Set the double-sided signal bandwidth to 2 kHz.

upConv = dsp.DigitalUpConverter(... 
     'InterpolationFactor',20,...
     'SampleRate',Fs,...
     'Bandwidth',2e3,...
     'StopbandAttenuation',55,...
     'PassbandRipple',0.2,...
     'CenterFrequency',50e3);

%
% Create a spectrum estimator to visualize the signal spectrum before and after upconverting.

window = hamming(floor(length(x)/10));
figure; pwelch(x,window,[],[],Fs,'centered')
title('Spectrum of baseband signal x')

% Upconvert the signal and visualize the spectrum.

 xUp = upConv(x); 
 window = hamming(floor(length(xUp)/10));
 figure; pwelch(xUp,window,[],[],20*Fs,'centered')
 title('Spectrum of upconverted signal xUp')

%
% Visualize the response of the interpolation filters.

 visualizeFilterStages(upConv)

% Copyright 2012 The MathWorks, Inc.