What is the purpose of this code?
2 次查看(过去 30 天)
显示 更早的评论
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 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!