What is the purpose of this code?

1 次查看(过去 30 天)
Michael
Michael 2023-2-20
回答: Luca Ferro 2023-2-21
What is the purpose of this code? Sorry, I do not have the function for signal, but I hope the code is enpugh for you to answer the question.
a) Plot the correlation between the signal and 100 different sine waves.
b) Plot the crosscorrelation between the signal and 100 different sine waves.
c) Plot the autocorrelation between the signal and 100 different sine waves.
d) Plot the covariance between the signal and 100 different sine waves.
e) Plot the crossvariance between the signal and 100 different sine waves.
clear all;
close all;
clc;
% What is the purpose of this code?
load signal;
fs = 100;
t = (1:length(signal))/fs;
for i = 1:100
f(i) = 0.35*i;
x = sin(2*pi*f(i)*t);
rxy = xcorr(signal,x);
rmax(i) = max(rxy);
end
plot(f,rmax,'k');
  1 个评论
the cyclist
the cyclist 2023-2-20
Please read this guide about getting help with homework, and edit your question accordingly.

请先登录,再进行评论。

回答(1 个)

Luca Ferro
Luca Ferro 2023-2-21
line per line
load signal; %load signal
fs = 100;
t = (1:length(signal))/fs; %create linspace (the time axis)
for i = 1:100 %cycle 100 times
f(i) = 0.35*i; %constant which changes value linearly every cycle, see below
x = sin(2*pi*f(i)*t); %generates a different sine wave at every cycle, the difference is guaranteed by f
rxy = xcorr(signal,x); %calculates the correlation between signal and x (it's an array), x is the sine generated in the current cycle
rmax(i) = max(rxy); %stores the maximum value of the above calculated array in a second array
end
plot(f,rmax,'k'); %plots every maximum correlation value stored
basically every cycle it creates a sine wave, compares it to the given signal, finds the maximum correlation, stores it. Once the cycle is done it plots it.

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by