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

I need the code for those question in (matlab) please Exercise 2 Cross correlati

ID: 1716500 • Letter: I

Question


I need the code for those question in (matlab) please

Exercise 2 Cross correlation of two discrete-time signals is defined by: Write a function crosscorrelationx,h to find the cross-correlation of two signals of arbitrary length and arbitrary starting points. Using time markers tic and toc, compare the performance of your code with the built-in xcorr function. Exercise 3 The auto-correlation of a discrete-time signal is defined by: he auto-correlation ofa discrete-time signalis defined by Generate a random Gaussian noise signal x[n using the function randn. Use the function crosscorrelation/x, h of Exercise 2 noise signal. Determine the effect of the length of the noise signal on the auto- correlation of the signal to find the auto-corelation of the

Explanation / Answer

Excercise 2:

Main code :

clc;
clear all;
close all;

% Lets take two signals randomly
x=[1 2 3 4.2 2.3];
h1=[1 2 3 4 1.2 3.4];
%cross correlation using crosscorrection(x,h) function
tic
k=length(h1);
for i=1:1:length(h1)
h(i)=h1(k);
k=k-1;
end

c=crosscorrelation(x,h);
l=length(x)+length(h);
fprintf('Cross Correlation of x[n] and h[n] using function');
c(2:l)
toc

%Cross correlation using bulit-in function xcorr
tic
fprintf('Cross Correlation of x[n] and h[n] using bulit-in function');
xcorr(x,h1)
toc

crosscorrelatio n(x,h) function:

function [c]=crosscorrelation(x,h)

l1=length(x);
l2=length(h);
c=zeros(1,l1+l2);
for i=1:1:l1
for j=1:1:l2
c(1,i+j)=c(1,i+j)+x(i)*h(j);
end
end

end

output:

Cross Correlation of x[n] and h[n] using functionans =
3.4000 8.0000 16.6000 28.8800 32.8600 33.5600 29.8000 18.3000 8.8000 2.3000
Elapsed time is 0.013455 seconds.
Cross Correlation of x[n] and h[n] using bulit-in functionans =
3.4000 8.0000 16.6000 28.8800 32.8600 33.5600 29.8000 18.3000 8.8000 2.3000 -0.0000
Elapsed time is 0.116602 seconds.

From the output, our function computes the Cross-Correlation comparately faster.

Excercise 3:

Main:

n=6;
x=randn(1,6)
k=length(x);
for i=1:1:length(x)
h(i)=x(k);
k=k-1;
end

c=crosscorrelation(x,h);
l=length(x)+length(h);
fprintf('Cross Correlation of x[n] and h[n] using function');
c(2:l)

output:

x =
0.8884 -1.1471 -1.0689 -0.8095 -2.9443 1.4384
Cross Correlation of x[n] and h[n] using functionans =
1.2779 -4.2656 1.1207 1.9617 -0.7793 14.6405 -0.7793 1.9617 1.1207 -4.2656 1.2779
>>