Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Week 14 Matlab project, ELEN420/Prof. Kraimeche In this assignment, we use Matla

ID: 2085080 • Letter: W

Question

Week 14 Matlab project, ELEN420/Prof. Kraimeche

In this assignment, we use Matlab to plot basic digital signal pulses: NRZ polar, RZ polar, half-sinusoid polar, and raised-cosine, and generate eye diagrams. The Matlab programs to be used are given on page 437 of the textbook. Run the Matlab programs to generate and plot:

NRZ, RZ, half-sinusoid, and raised cosine pulses

The eye diagrams for the 4 types of pulses above

The original Matlab programs are reproduced below:

% (pnrz.m)

% generating a rectangular pulse of width T

% Usage function pout=pnrz(T);

function pout=prect(T);

% ----------------------------------------------------

% (prz.m)

% generating a rectangular pulse of width T/2

% Usage function pout=prz(T);

function pout=prz(T);

pout=[zeros(1,T/4) ones(1,T/2) zeros(1,T/4)];

% -------------------------------------------------------

% (psine.m)

% generating a sinusoid pulse of width T

function pout=psine(T);

% --------------------------------------------------------

% (prcos.m)

function y=prcos(rollfac,length, T)

% rollfac = 0 to 1 is the rolloff factor

% length is the onesided pulse length in the number of T

% length = 2T+1;

% T is the oversampling rate

y=rcosfir(rollfac, length, T,1, ’normal’);

% -------------------------------------------------------------

% (binary_eye.m)

% generate and plot eyediagrams

data = sign(randn(1,400));% Generate 400 random bits

dataup=upsample(data, Tau); % Generate impulse train

ynrz=conv(dataup,pnrz(Tau)); % Non-return to zero polar

yrcos=conv(dataup,prcos(0.5,Td,Tau)); % rolloff factor = 0.5

yrcos=yrcos(2*Td*Tau:end-2*Td*Tau+1); % generating RC pulse train

eye1=eyediagram(yrz,2*Tau,Tau,Tau/2);title(’RZ eye-diagram’);

eye2=eyediagram(ynrz,2*Tau,Tau,Tau/2);title(’NRZ eye-diagram’);

eye3=eyediagram(ysine,2*Tau,Tau,Tau/2);title(’Half-sine eye-diagram’);

eye4=eyediagram(yrcos,2*Tau,Tau); title(’Raised-cosine eye-diagram’);

Program codes for Matlab

Explanation / Answer

%{
In this assignment, we use Matlab to plot basic digital signal pulses: NRZ polar,
RZ polar, half-sinusoid polar, and raised-cosine, and generate eye diagrams.
The Matlab programs to be used are given on page 437 of the textbook. Run the Matlab
programs to generate and plot:
NRZ, RZ, half-sinusoid, and raised cosine pulses
%}


close all,
clear all,
clc,

h=[1 0 0 1 1 0 1 0 1 0];

%%%%%%%%%% NRZ Plot %%%%%%%%%%%%%
figure,
for r=1:length(h)
Y=[];
t = (r-1):0.001:r;
length(t)
for c=1:length(t)
if(h(r)==0),
Y(c) = -1;
end
if(h(r)==1),
Y(c) = 1;
end
end
d=plot(t,Y);grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5])
end
title('NRZ Polar PLOT');
%%%%%%%%%% NRZ Plot %%%%%%%%%%%%%

%%%%%%%%%% RZ Plot %%%%%%%%%%%%%
figure,
h=[1 0 0 1 1 0 1 0 1 0];
for r=1:length(h)
Y=[];
t = (r-1):0.001:r;
length(t)
for c=1:length(t)
if(h(r)==0),
Y(c) = 0;
end
if(h(r)==1),
Y(c) = 1;
end
end
d=plot(t,Y);grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5])
end
title('RZ Non-Polar PLOT');
%%%%%%%%%% RZ Plot %%%%%%%%%%%%%

%%%%%%%%%% Half Sinusoid Polar Plot %%%%%%%%%%%%%
figure,
SignalFreq = 5;
Ns = 100;
Count=1;
Half_Positive=[];
Half_Negative=[];
Count_Pos=1;
Count_Neg=1;
for i=0:Ns
Signal(Count) = 1.5*sin(2*pi*SignalFreq*(i/Ns-1));
if(Signal(Count) >=0), Half_Positive(Count_Pos)=Signal(Count); Count_Pos=Count_Pos+1; end
if(Signal(Count) <= 0), Half_Negative(Count_Neg)=Signal(Count); Count_Neg=Count_Neg+1; end
Count=Count+1;
end

subplot(3,1,1);
d=plot(Signal); grid on;
set(d,'LineWidth',2.5);
axis([0 length(Signal)-1 -1.5 1.5])
str = strcat('Signal Freq. = ',num2str(SignalFreq),' Hz');
text(70,0.8,str);
str = strcat('Sampling Freq. = ',num2str(Ns),' Hz');
text(70,0.5,str);
xlabel('--- No. of Samples --->');
ylabel('--- Amplitude --->');

subplot(3,1,2); d=plot(Half_Positive); grid on; title('Sin Wave - Positive Half');
set(d,'LineWidth',2.5);
axis([0 length(Signal)-1 -1.5 1.5])

subplot(3,1,3); d=plot(Half_Negative); grid on; title('Sin Wave - Negative Half');
set(d,'LineWidth',2.5);
axis([0 length(Signal)-1 -1.5 1.5])
%%%%%%%%%% Half Sinusoid Polar Plot %%%%%%%%%%%%%


%%%%%%%%%% Raised Cosine Plot %%%%%%%%%%%%%
figure,
SignalFreq = 5;
Ns = 100;
Count=1;
Signal=[];
RaisedSignal=[];
RaiseVal=5;
for i=0:Ns
Signal(Count) = 1.5*cos(2*pi*SignalFreq*(i/Ns-1));
RaisedSignal(Count)=RaiseVal + Signal(Count);
Count=Count+1;
end

subplot(2,1,1);
d=plot(Signal); grid on;
set(d,'LineWidth',2.5);
axis([0 length(Signal)-1 -1.5 1.5])
title('Cosine Wave');
xlabel('--- No. of Samples --->');
ylabel('--- Amplitude --->');

subplot(2,1,2);
d=plot(RaisedSignal); grid on;
set(d,'LineWidth',2.5);
%axis([0 length(Signal)-1 -1.5 1.5])
title('Raised Cosine Wave ar Raised Val');
xlabel('--- No. of Samples --->');
ylabel('--- Amplitude --->');


%%%%%%%%%% Half Sinusoid Polar Plot %%%%%%%%%%%%%

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote