What is the purpose of this code?

1 visualización (últimos 30 días)
Michael
Michael el 20 de Feb. de 2023
Respondida: Luca Ferro el 21 de Feb. de 2023
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 comentario
the cyclist
the cyclist el 20 de Feb. de 2023
Please read this guide about getting help with homework, and edit your question accordingly.

Iniciar sesión para comentar.

Respuestas (1)

Luca Ferro
Luca Ferro el 21 de Feb. de 2023
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.

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by