06.06.2022 Views

B. P. Lathi, Zhi Ding - Modern Digital and Analog Communication Systems-Oxford University Press (2009)

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6. 9 MATLAB Exercises 315

% ts new sampling period

% NOTE : td*fs must be a positive integer;

% Function outputs :

%

s out - sampled output

%

sq_out - sample-and-quantized output

%

sqh_out- sample, quantize, and hold output

%

Delta - quantization interval

%

SQNR - actual signal to quantization noise ratio

if (rem(ts/td, 1)==0)

nfac=round (ts/td) ;

p_zoh=ones (l,nfac) ;

s_out=downsampl e(sig_in,nfac) ;

[sq_out ,Delta, SQNR] =uniquan (s_out ,L) ;

s_out=upsampl e(s_out ,nfac) ;

sqh_out=kron (sq_out ,p_zoh) ;

sq_out=upsample (sq_out ,nfac );

else

warning ('Error ! ts/td is not an integer! ');

s_out= [] ;sq_out= [l ;sqh_out= [l ;Delta= [] ;SQNR= [l ;

end

end

The MATLAB program ExPCM . m provides a numerical example that uses these two

MATLAB functions to generate PCM signals.

% (ExPCM .m)

% Example of sampling, quantization , and zero-order hold

clear;clf;

td=0 .002 ;

t= [ O : td : 1 . l ;

%original sampling rate 500 Hz

%time interval of 1 second

xsig=sin (2*pi*t) -sin (6*pi*t) ; % 1Hz+3Hz sinusoids

Lsig=length (xsig) ;

Lfft=2-ceil ( log2 (Lsig) +l) ;

Xsig=fftshift (fft (xsig,Lfft) );

Fmax=l/(2*td) ;

Faxis=linspace (-Fmax , Fmax,Lfft) ;

ts=0 .02;

%new sampling rate 50Hz .

Nfact=ts/td;

% send the signal through a 16-level uniform quantizer

[s_out, sq_out,sqh_outl, Delta, SQNR] =sampandquant (xsig , 16,td, ts) ;

% obtained the PCM signal which is

% - sampled , quantized, and zero-order hold signal sqh_out

% plot the original signal and the PCM signal in time domain

figure (l) ;

subplot (211) ;sfigl=plot (t,xsig, 'k' ,t, sqh_outl (l:Lsig) , 'b');

set (sfigl , 'Linewidth ' ,2) ;

title ('Signal {\it g} ({\it t} ) and its 16 level PCM signal ')

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!