I have Implemented Cyclostationary detector for spectrum sensing in AWGN channel in Matlab but I am getting vague result. As it performance doesn't vary with change in SNR. Its very strange result for me. I don't know what mistake I am doing in it. I am attaching my codes please have look and comment. Here I am finding cyclostationary feature of signal for its detection. Firstly I tried to Out FFT of a signal then shift its frequency by +alpha of tranform and -alpha to its conjugate. Then I multiplied both to taken sum of all. Thats how all theory explain about cyclostationary feature detection I will very grateful if somebody can help me in this.
function Pd=Cyclo_AWGN(Pf,snr_avg,n,N,Sim_Times)
% Pf= Probablity of false alarm
% n= length of data
% N= length of fft
% Sim_Times= Iteration
ln=0:n-1;
Over_Num = 0;
Th_awgn= sqrt(-2*log(Pf)/n); % threshold
for kk = 1:Sim_Times
phi= randi([-180,180],1,n);
phi=phi*2*pi/360;
x=sin(0.32*pi*ln+phi);
Recv_Signal = x; % Recived Signal
Noise_awgn = randn(1,n)+1i*randn(1,n);
AvgPower_Noise_awgn=sum(abs(Recv_Signal).^2)/snr_avg; %average power of noise
std_Noise_awgn = sqrt(AvgPower_Noise_awgn);
Noise_awgn = std_Noise_awgn*Noise_awgn;
norm_signal_awgn = Recv_Signal/std_Noise_awgn; %Normalized signal sample
norm_noise_awgn = Noise_awgn/std_Noise_awgn; %Normalized Noise sample
Recv_sig_awgn = norm_signal_awgn + norm_noise_awgn; % Normalized received signal for detection
X=zeros(2*N+1);
Y=zeros(2*N+1);
Ts=1/N;
for f=-N:N
d=exp(-j*2*pi*f*ln*Ts);
xf= Recv_sig_awgn.*d;
n_r=n:-1:1;
X(f+N+1)=sum(xf(n_r));
Y(f+N+1)=conj(sum(xf(n_r)));
end
alpha=10;
f=5;
f1=f+floor(alpha/2)+(floor(-((N-1)/2)):floor((N-1)/2));
f2=f-floor(alpha/2)+(floor(-((N-1)/2)):floor((N-1)/2));
S(kk)=sum(X(f1+N+1).*Y(f2+N+1))/N;
S(kk)=abs(S(kk))/n;
if S(kk)>Th_awgn
Over_Num = Over_Num +1; %decide 1 or 0, present or absent
end
end
Pd = Over_Num / Sim_Times; % Simulated Pd}
You need to take this one step at a time. I see errors in the signal generation as well as the statistic calculation.
First, ensure that you are creating a cyclostationary signal! I ran the signal-generation code in the function above, and also looked at it. It looks like a random phase modulation. Try first to generate a signal you know is cyclostationary, like BPSK or analog AM.
Second, you tried a cycle frequency of 10. But it looks like you are using (implicitly) a sampling rate of 1 (at least in the signal-generation part), which is fine. But then alpha must lie in the interval [-1,1].
Third, rewrite the code to more clearly separate the signal generation, spectral correlation function estimation, and detection-statistic calculation. Make sure that the spectral correlation function is first being estimated correctly before you try to put it in a loop for Pd/Pfa calculation.
Have a look at Chapter 18 of the book "Cognitive Radio Technology", Second Edition. The end of the chapter has some exercises that might help you fix up your code.
Good luck!