%% Convert Sample Rate of Sinusoid
%
% *Note*: If you are using R2016a or an earlier release, replace each call 
% to the object with the equivalent |step| syntax. For example, |obj(x)| 
% becomes |step(obj,x)|.
% 
% Create a multistage sample rate converter with default properties. The 
% converter converts from 192 kHz to 44.1 kHz in three stages.

src = dsp.SampleRateConverter;
%% 
% Use |src| to convert the sample rate of a noisy sinusoid. The sinusoid 
% has a frequency of 20 kHz and is sampled for 0.1 s. 
%%
f = 20e3;

FsIn = src.InputSampleRate;
FsOut = src.OutputSampleRate;

t1 = (0:1/FsIn:0.1-1/FsIn)';

sIn = sin(2*pi*f*t1) + randn(size(t1));
%% 
% Estimate the power spectral density of the input.
%%
hsa = dsp.SpectrumAnalyzer('SampleRate',FsIn,'YLimits',[-40 40]);
hsa(sIn)
%% 
% Convert the sample rate of the signal. Estimate the power spectral density 
% of the output.
%%
sOut = src(sIn);

hsb = dsp.SpectrumAnalyzer('SampleRate',FsOut,'YLimits',[-40 40]);
hsb(sOut)

%% 
% Copyright 2012 The MathWorks, Inc.