%%% rtl_init.m %%%
% Purpose of this function is to initialize the RTL SDR object and set its
% basic parameters

function [rtlsdr,fs,fc,f_min,f_max,nfft] = rtl_init...
(SamplesPerFrame,SampleRate,CenterFrequency,EnableTunerAGC,TunerGain,OutputDataType)
% INPUT EXAMPLE rtl_init(32768,2.4e6,88423000,0,8.7)
rtlsdr = comm.SDRRTLReceiver;
rtlsdr.SamplesPerFrame = SamplesPerFrame;
rtlsdr.SampleRate = SampleRate;
rtlsdr.CenterFrequency = CenterFrequency;
rtlsdr.EnableTunerAGC = EnableTunerAGC;
rtlsdr.TunerGain = TunerGain;
rtlsdr.OutputDataType = OutputDataType;

fs = rtlsdr.SampleRate; 
fc = rtlsdr.CenterFrequency;
f_min = fc - fs/2;
f_max = fc + fs/2;

nfft = SamplesPerFrame;
end