What is the purpose of this code?

3 visualizzazioni (ultimi 30 giorni)
Michael
Michael il 20 Feb 2023
Risposto: Luca Ferro il 21 Feb 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 Commento
the cyclist
the cyclist il 20 Feb 2023
Please read this guide about getting help with homework, and edit your question accordingly.

Accedi per commentare.

Risposte (1)

Luca Ferro
Luca Ferro il 21 Feb 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.

Categorie

Scopri di più su Get Started with Signal Processing Toolbox in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by