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

Please change this MATLAB script in order to answer this problem below. It needs

ID: 2250048 • Letter: P

Question

Please change this MATLAB script in order to answer this problem below. It needs to show the graph and correlation coefficient requested in item 1.

%% Initialization and generation of V.A.s
tic
close all;clear;clc
N_x = 1e5; %Number of values generated for X
p=linspace(0,1,1e2); %Generates vector p between 0 and 1 with 1e2 (100) values
x=zeros(length(p),N_x); %Initializes vector X
y=zeros(size(x)); %Initializes vector Y
rho=zeros(1,size(x,1)); %Initializes vector rho
for i=1:length(p) %Loop for generates random variable p
for j=1:N_x
x(i,j)=rand;
% x(i,j)=randn;
if x(i,j)<=p(i)
x(i,j)=1;
else
x(i,j)=0;
end
end
end

for i=1:size(x,1) %Loop for generates random variable X
for j=2:size(x,2)
% yy(i,j-1)=mod((x(i,j)+x(i,j-1)),2); %Mod 2 = XOR
y(i,j-1)=xor(x(i,j),x(i,j-1)); %XOR
end
end

%% number 1)
for i=1:size(x,1)
Rxy=corrcoef(x(i,:),y(i,:)); %Correlation between X and Y
rho(i)=Rxy(1,2); %Stores corr values
end

plot(p,rho) %Plot

%% number 2)
ind = find(isnan(rho) == 1); %Returns the index where correlation is non-existent (NaN)

num2str(p(ind))]) %Displays p values for nonexistent relationship

ORIGINAL PROBLEM

et be a binary sequence (0 or 1) where the probability of appearing a 1 is . This sequence is p...

This sequence is passed by a digital filter whose output is given by

Explanation / Answer

Hello,
          Please find the answer attached as under. Please give a thumbs up rating if you find the answer useful! Have a rocking day ahead!
The code is working properly as is. The only change I made was to add the x and y labels in the final graph. Also the comments at a couple of places were wrong. The first loop generates the random variable x, and not p. p is already intialised. The second loop generates output Y of the filter.

*********************** Matlab code ****************

%% Initialization and generation of V.A.s
tic
close all;clear;clc
N_x = 1e5;                           %Number of values generated for X
p=linspace(0,1,1e2);                 %Generates vector p between 0 and 1 with 1e2 (100) values
x=zeros(length(p),N_x);                 %Initializes vector X
y=zeros(size(x));                       %Initializes vector Y
rho=zeros(1,size(x,1));                 %Initializes vector rho
for i=1:length(p)                       %Loop for generates random variable x
    for j=1:N_x
        x(i,j)=rand;
% x(i,j)=randn;
         if x(i,j)<=p(i)
             x(i,j)=1;
         else
             x(i,j)=0;
         end
     end
end
for i=1:size(x,1)               %Loop for generates output Y of filter
     for j=2:size(x,2)
% yy(i,j-1)=mod((x(i,j)+x(i,j-1)),2); %Mod 2 = XOR
         y(i,j-1)=xor(x(i,j),x(i,j-1));      %XOR
     end
end
%% number 1)
for i=1:size(x,1)
     Rxy=corrcoef(x(i,:),y(i,:));        %Correlation between X and Y
    rho(i)=Rxy(1,2);                     %Stores corr values
end
plot(p,rho)                              %Plot
xlabel('p');
ylabel('Correlation coefficient rho')
%% number 2)
ind = find(isnan(rho) == 1); %Returns the index where correlation is non-existent (NaN)
    num2str(p(ind))      %Displays p values for nonexistent relationship

************** End of code **********