PCS Programs
PCS Programs
7
PCM Illustration: Sampling, Quantization and
Encoding
Clc;
Clear all;
Close all;
f=2;
fs=20*f;
t=0:1/fs:1;
a=2;
% input signal
x=a*sin(2*pi*f*t);
subplot(2,2,1);
plot(t,x,'r-');
grid on;
xlabel('time');
ylabel('amplitude');
title('i/p signal');
% quantization
x1=x+a; q_op=round(x1);
subplot(2,2,2);
plot(t,q_op,'k+-');
grid on;
xlabel('time');
ylabel('amplitude');
title('quantised signal');
%encoding
enco=de2bi(q_op,'left-msb');
[m,n]=size(enco);
y3=reshape(enco',1,m*n);
t=linspace(0,1.23,1230);
for i=1:length(y3)
if y3(i)==1
signal(1,i*10-9:i*10)=1;
else
signal(1,i*10-9:i*10)=-1;
end
end
subplot(2,2,3);
plot(t,signal);
grid on;
xlabel('time');
ylabel('amplitude');
title('PCM signal');
%decoding
for i=1:length(signal)/10
if signal(1,i*10-9:i*10)==1
y4(i)=1;
else
y4(i)=0;
end
end
y5=(reshape(y4,n,m))';
deco=bi2de(y5,'left-msb');
xr=deco-a;
t=0:1/fs:1;
subplot(2,2,4);
plot(t,xr);
grid on;
xlabel('time');
ylabel('amplitude');
Experiment No. 8
Generate a) NRZ, RZ and Raised cosine pulse b) Generate
and plot eye diagram
clear all;
close all;
warning off
n=[1 0 1 1 1 0 0 1];
for m=1:length(n)
if n(m)==1
nn(m)=2;
else nn(m)=-2;
end
end
t=0:0.00001:length(n);
for j=1:length(t)
y(j)=nn(i);
y(j)=0;
else i=i+1;
a=a+1;
b=b+1;
end
end
subplot(2,1,1);
plot(t,y,'k');
grid on;
ylabel('time');
xlabel('amplitude');
i=1;
t=0:0.00001:length(n);
for j=1:length(t)
if t(j) <i
y(j)==nn(i);
else
i=i+1;
end
end
subplot(2,1,2);
plot(t,y,'k');
grid on;
xlabel('time');
ylabel('amplitude');
clc;
clear all;
close all;
x=[1 1 1 0 0 1 0 1 1 0];
fs=20;
fd=1;
%rasied cosine
y=rcosine(fd,fs);
figure(1);
plot(y);
title('Raised cosine');
%eye diagram
delay=5;
r=0.5;
rcv=rcosflt(x,fd,fs,'fir/normal',r,delay);
n=fs/fd;
eyediagram(rcv,n);
Experiment No. 9
Generate the Probability density function of Gaussian
distribution function
% Parameters
x = -5:0.1:5;
% Compute PDF
% Plot PDF
figure;
xlabel('x');
ylabel('PDF');
grid on;
Experiment No. 10
Display the signal and its spectrum of an audio signal
audioFile = 'your_audio_file.wav';
t = (0:length(y)-1) / Fs;
figure;
subplot(2, 1, 1);
plot(t, y);
title('Time-Domain Signal');
xlabel('Time (s)');
ylabel('Amplitude');
N = length(y);
Y = fft(y);
f = (0:N-1) * Fs / N;
plot(f, abs(Y));
title('Frequency Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
% You can also use the following line to display the spectrum in dB scale
plot(f, 20*log10(abs(Y)));
ylabel('Magnitude (dB)');
% Adjust plot
grid on;