%psd.m
I=round(rand(1,1000))*2-1;
Q=round(rand(1,1000))*2-1;
DATAI=[];
DATAQ=[];
for i=1:1:1000
DATAI=[DATAI ones(1,100)*I(i)];
DATAQ=[DATAQ ones(1,100)*Q(i)];
end
t=0:0.01:10000;
t=t(1:1:length(DATAI));
X=DATAI.*cos(2*pi*1*t)-DATAQ.*sin(2*pi*1*t)+2*randn(1,length(DATAI));
figure
subplot(4,1,1)
plot(X(1:1:1000))
%Power Spectral Estimation
%Barlett method
s=0;
for k=1:1:5
temp=X((k-1)*1000+1:1:(k-1)*1000+1000);
s=s+abs(fft(temp)).^2;
end
s=s/5;
subplot(4,1,2)
plot(s/max(s))
%Welch method
s=0;
for k=1:1:5
temp=X((k-1)*500+1:1:(k-1)*500+1000);
temp=temp.*bartlett(length(temp))';
s=s+abs(fft(temp)).^2;
end
s=s/5;
subplot(4,1,3)
plot(s/max(s))
%Blackman and Tuckey method
A=conv(X(1:1:500),[zeros(1,500) X(500:-1:1)]);
B=A(501:1:length(A));
C=B.*bartlett(length(B))';
s=abs(fft(C));
subplot(4,1,4)
plot(s/max(s))
