In: Electrical Engineering
1. Open m file of sampandquant, uniquan and Prelab4 in MATLAB.
a. Set the quantization levels of PCM (L) as 2 and 32. Compare your results.
b. Why did we choose the cut-off frequency of the ideal LPF as 30 Hz. What happens for small or very big values of the cut-off frequency?
c. Change the message signal as : xsig = cos(2pit) + cos(2pit)
d. First set the quantization levels of PCM (L) as 2 and 32. Compare your results. Then, set different values of L and compare your results.
e. What should be the cut off frequency of the ideal low pass filter for the signal given in part (c) so that the original and the recovered signals will look like each other?
Part A:
% (ExPCM.m)
% Example of sampling, quantization, and zero-order hold
clear all; close all; clc;
td=0.002; %original sampling rate 500 Hz
t=0:td:1.; % 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)+1);
Xsig=fftshift(fft(xsig,Lfft));
Fmax=1/(2*td);
Faxis=linspace(-Fmax,Fmax,Lfft);
ts=0.02; % new sampling rate = 50 Hz
Nfact=ts/td;
% send the signal through a 16-level uniform quantizer
[s_out,sq_out,sqh_out1,Delta,SQNR]=sampandquant(xsig,2,td,ts);
% obtained the PCM signal which is
% - sampled, quantized, and zero-order hold signal sqh_out
% plot the orignal signal and the PCM signal in time domain
figure(1);
subplot(211);sfig1=plot(t,xsig,'k',t,sqh_out1(1:Lsig),'b');
set(sfig1,'Linewidth',2);
title('Signal {\it g}({\it t}) and its 2 level PCM signal');
xlabel('time (sec.)');
% send the signal throuhg a 4-level uniform quantizer
[s_out,sq_out,sqh_out2,Delta,SQNR]=sampandquant(xsig,32,td,ts);
% obtained the PCM signal which is
% - sampled, quantized, and zero-order hold signal sqh_out
% plot the orignal signal and the PCM signal in time domain
subplot(212);sfig2=plot(t,xsig,'k',t,sqh_out2(1:Lsig),'b');
set(sfig2,'Linewidth',2);
title('Signal {\it g}({\it t}) and its 32 level PCM signal');
xlabel('time (sec.)');
Lfft=2^ceil(log2(Lsig)+1);
Fmax=1/(2*td);
Faxis=linspace(-Fmax,Fmax,Lfft);
SQH1=fftshift(fft(sqh_out1,Lfft));
SQH2=fftshift(fft(sqh_out2,Lfft));
% Now use LPF to filter the two PCM signals
BW=10; %Bandwidth is no larger than 10Hz
H_lpf=zeros(1,Lfft);H_lpf(Lfft/2-BW:Lfft/2+BW-1)=1; %ideal
LPF
S1_recv=SQH1.*H_lpf; % ideal filtering
s_recv1=real(ifft(fftshift(S1_recv))); % reconstructed
f-domain
s_recv1=s_recv1(1:Lsig); % reconstructed t-domain
S2_recv=SQH2.*H_lpf; % ideal filtering
s_recv2=real(ifft(fftshift(S2_recv))); % reconstructed
f-domain
s_recv2=s_recv2(1:Lsig); % reconstructed t-domain
% Plot the filtered signals against the original signal
figure(2);
subplot(211); sfig3=plot(t,xsig,'b-',t,s_recv1,'b-.');
legend('original','recovered');
set(sfig3,'Linewidth',2);
title('Signal {\it g} ({\it t}) and filtered 2-level PCM
signal');
xlabel('time (sec.)');
subplot(212); sfig4=plot(t,xsig,'b-',t,s_recv2,'b-.');
legend('original','recovered');
set(sfig4,'Linewidth',2);
title('Signal {\it g} ({\it t}) and filtered 32-level PCM
signal');
xlabel('time (sec.)');
--------------------------------
Result:
Part B:
The maximum frequency componant in the signal is 8*pi so in order to recover this signal lpf cutoff is set at 30Hz
if it is small we will lost the signal and canno recover it. if it is too big then image freq will be there in the output.
==============================
Part C
------------------------------------------------------------------
% (ExPCM.m)
% Example of sampling, quantization, and zero-order hold
clear all; close all; clc;
td=0.002; %original sampling rate 500 Hz
t=0:td:1.; % time interval of 1 second
xsig=cos(2*pi*t)+cos(2*pi*t); % 1Hz+3Hz sinusoids
Lsig=length(xsig);
Lfft=2^ceil(log2(Lsig)+1);
Xsig=fftshift(fft(xsig,Lfft));
Fmax=1/(2*td);
Faxis=linspace(-Fmax,Fmax,Lfft);
ts=0.02; % new sampling rate = 50 Hz
Nfact=ts/td;
% send the signal through a 16-level uniform quantizer
[s_out,sq_out,sqh_out1,Delta,SQNR]=sampandquant(xsig,2,td,ts);
% obtained the PCM signal which is
% - sampled, quantized, and zero-order hold signal sqh_out
% plot the orignal signal and the PCM signal in time domain
figure(1);
subplot(211);sfig1=plot(t,xsig,'k',t,sqh_out1(1:Lsig),'b');
set(sfig1,'Linewidth',2);
title('Signal {\it g}({\it t}) and its 2 level PCM signal');
xlabel('time (sec.)');
% send the signal throuhg a 4-level uniform quantizer
[s_out,sq_out,sqh_out2,Delta,SQNR]=sampandquant(xsig,32,td,ts);
% obtained the PCM signal which is
% - sampled, quantized, and zero-order hold signal sqh_out
% plot the orignal signal and the PCM signal in time domain
subplot(212);sfig2=plot(t,xsig,'k',t,sqh_out2(1:Lsig),'b');
set(sfig2,'Linewidth',2);
title('Signal {\it g}({\it t}) and its 32 level PCM signal');
xlabel('time (sec.)');
Lfft=2^ceil(log2(Lsig)+1);
Fmax=1/(2*td);
Faxis=linspace(-Fmax,Fmax,Lfft);
SQH1=fftshift(fft(sqh_out1,Lfft));
SQH2=fftshift(fft(sqh_out2,Lfft));
% Now use LPF to filter the two PCM signals
BW=10; %Bandwidth is no larger than 10Hz
H_lpf=zeros(1,Lfft);H_lpf(Lfft/2-BW:Lfft/2+BW-1)=1; %ideal
LPF
S1_recv=SQH1.*H_lpf; % ideal filtering
s_recv1=real(ifft(fftshift(S1_recv))); % reconstructed
f-domain
s_recv1=s_recv1(1:Lsig); % reconstructed t-domain
S2_recv=SQH2.*H_lpf; % ideal filtering
s_recv2=real(ifft(fftshift(S2_recv))); % reconstructed
f-domain
s_recv2=s_recv2(1:Lsig); % reconstructed t-domain
% Plot the filtered signals against the original signal
figure(2);
subplot(211); sfig3=plot(t,xsig,'b-',t,s_recv1,'b-.');
legend('original','recovered');
set(sfig3,'Linewidth',2);
title('Signal {\it g} ({\it t}) and filtered 2-level PCM
signal');
xlabel('time (sec.)');
subplot(212); sfig4=plot(t,xsig,'b-',t,s_recv2,'b-.');
legend('original','recovered');
set(sfig4,'Linewidth',2);
title('Signal {\it g} ({\it t}) and filtered 32-level PCM
signal');
xlabel('time (sec.)');
--------------------------------------------------
result
--------------------------------
Part D;
The maximum freq content in the signal will be 4*pi so we will select lpf freq as 15Hz