clear;
clc;
fs = 1024;
len = 1024;
t = 0:1/fs:(len-1)/fs;
x = 3.7 * sin(2pi16t);
y = 1.9 * sin(2pi32t);
w = blackman(1024, ‘periodic’);
[p, f] = cpsd(x, y, w, 0, 1024, fs);
plot(f, abs§)
title(‘cpsd’)
max(abs§)
z = xcorr(x, y);
cnx = z(len:end) + [0 z(1:len-1)];
w = w’;
x1 = cnx .* w;
cxk1 = fft(x1, 1024);
p1=abs(cxk1) * 2 / (1024 * fs);
w1 = w .* w;
u = sum(w1) / 1024;
%p = p1/u;
p = p1;
f = 0:fs/1024:fs/2;
figure
plot(f, p(1:1024/2+1))
title(‘xcorr’)
max§