www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/UpconvertASineWaveSignalExample.m

    %% Upconvert a Sine Wave Signal
% Create a digital up converter object that upsamples a 1 KHz sinusoidal 
% signal by a factor of 20, and up converts 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).

%% Initialization
% Create a sine wave generator to obtain the 1 KHz sinusoidal signal
% with a sample rate of 6 KHz.
 Fs = 6e3; % Sample rate
 hSig = dsp.SineWave('Frequency',1000,'SampleRate', Fs,'SamplesPerFrame',1024);
 x = hSig(); % generate signal
 
%%
% Create a DUC object. Use minimum order filter designs and set the
% passband ripple to 0.2 dB and the stopband attenuation to 55 dB. Set
% the double sided signal bandwidth to 2 KHz. 
hDUC = 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 up converting.
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 = hDUC(x); % up convert
 window = hamming(floor(length(xUp)/10));
 figure; pwelch(xUp,window,[],[],20*Fs,'centered')
 title('Spectrum of up converted signal xUp')
 
 %%
 % Visualize the response of the interpolation filters 
 visualizeFilterStages(hDUC)