0% found this document useful (0 votes)
7 views2 pages

Matlab

The document contains a MATLAB program that computes the cross-correlation and autocorrelation of two sequences, x(n) and y(n). It defines the sequences, calculates their correlations, and verifies the energy property of the signal. Additionally, it includes code to plot the sequences and their correlation results.

Uploaded by

Chayanika Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Matlab

The document contains a MATLAB program that computes the cross-correlation and autocorrelation of two sequences, x(n) and y(n). It defines the sequences, calculates their correlations, and verifies the energy property of the signal. Additionally, it includes code to plot the sequences and their correlation results.

Uploaded by

Chayanika Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PUBLISH VIEW Search (Ctrl+Shift+5pace) ?

Section Break
Code Issues
Run and Advance
ctor Generate Run Run Step Stop
Debugger Test Section Run to End
CODE ANALYZE TEST SECTION RUN

<lamp.m X SIne.m untitled. mx untitled2.mx untitled3.m X labhw.m X Fiqure 1 X +


IMATLAB Drive/labhw.m
1 % MATLAB Program to compute Cross-Correlation and Autocorrela Sequence x(n)
2
3 clc; clear; close all;
4
% Define the sequences
6 X = [1 2 3 4]; % Example sequence x(n) 0
3
0.5 1 1.5 2 2.5 3.5 4 4.5
y =[4 3 2 1]; % Example sequence y(n)
Correlation
30
Cross-Correlation of x(n)and y(n)
% Compute cross-correlation
10 cross_corr = Xcorr(x, y); 20
11 disp('Cross-Correlation of x(n) and y(n):);
12 disp(cross_corr); 10
13
14 2
% Compute autocorrelation of x(n)
15 auto_corr_x = xcorr(x) ; Correlation Lag
16 AutocorTelation of x(n)
disp('Autocorrelation of x(n):);
17 disp(auto_ corr_x);
13 20
19 %Verify the property: Energy of the signal= autocorrelation
20 energy_X = Sum(x. ^2);
21 auto _corr_x_zero_lag = auto_corr_x(length(x) ); % Middle value
22 Lag
23

ommand WindoW
lew to MATLAB? See resources for Getting Started.
utocorrelation of x(n):
4.0000 11.0000 20.0090 30.0000 20.000 11.0000 4.0000

ergy of x(n)30
tocorrelation of x(n) at zero lag: 30

Zoom: 100% UTF-8 CRLF Script Ln 45 Co! 23


Theory of Computation | Regule MATLAB

atworks.com

APPS EDITOR PUBLISH VIEW Search (Ctrl+Shift +Space) Anusha

Section Break
Code Issues
Q Find Run and Advance
oo Refactor Debugger Generate Run Run Step Stop
Bookmark Test Section Run to End
NAVIGATE CODE ANALYZE TEST SECTION RUN

AB Drive
:
<lamp.m X sine.m × untitled.m X untitled2.m X untitled3.m X labhW.m X Figure 1 ×
IMATLAB Drive/labhw.m
25 Sequence x(n)
4
26 % Plot the results
27
figure;
28
29 subplot(3,1,1);
stem(x);
31 title(' Sequencè x(n)'); 0.5 1.5 25 3.5 4.5

xlabel('n'); Cross-Corelation of x(n) and y(n)


33 ylabel ('x(n)'); 30
B4 I.
7 20
35 subplot (3,1, 2) ; 10
36 stem(-length(y)+1:length (y)-1, cross_corr);
37 title("Cross-Correlation of x(n) and y(n)');
2 2
38 xlabel('Lag);
39 ylabel ('Correlation' ); Lag
40 30
Autocorrelation of x(n)
Size :Class
41 subplot(3,1,3) ; 20
42 stem(-length(x)+1:length(x)-1, auto_corr_x);
1x7 double 43 title('Autocorrelation of x(n)'); 10
1x1 doubie
44 xlabel(Lag' );
1x7 double
45 ylabel(Correlation'); -2 2
Lag
1x1 double
1x4 double Command Window
1x4 double
New to MATLAB? See resources for Getting Started.
Autocorrelation ofx(n):
4.000 11.0000 20.0000 30.0000 20.0000 11.0000 4.000O

Energy of x(n): 30
Autocorrelation of x(n) at zero lag: 30

Zoom: 100% UTF-8 CRLF Script Ln 45 Co! 23

You might also like