write a matlab program to find the auto correlation of the finite length sequence x(n)=[1 4 1 3]. plot the input and output sequences in matlab

To find the auto correlation of the finite length sequence x(n)=[1 4 1 3] in Matlab, we can use the xcorr function. Here is the code:

main.m
% Define the finite length sequence x(n)
x = [1 4 1 3];

% Find the autocorrelation of x(n)
r = xcorr(x);

% Plot the input and output sequences
subplot(2,1,1)
stem(x)
title('Input Sequence')
xlabel('Sample Index')
ylabel('Amplitude')

subplot(2,1,2)
stem(r)
title('Autocorrelation of Input Sequence')
xlabel('Sample Index')
ylabel('Amplitude')
345 chars
19 lines

This code first defines the sequence x. It then calculates the autocorrelation of x using the xcorr function. Finally, it plots the input sequence and the autocorrelation using the stem function, with appropriate titles and labels.

The resulting plot should show the input sequence as a stem plot, and the autocorrelation as another stem plot, with the same number of samples as the input sequence.

related categories

gistlibby LogSnag