You are on page 1of 3

%%%% frequency-smoothing window ?????????

%
SSCA
%%%%
falfa
%
clc;
clear all;
close all;
tic
snr_dB = -50:0.0244:0; % SNR in decibels
snr = 10.^(snr_dB./10); % Linear Value of SNR
l=100
Rb=2;
%
Ts=1/Rb; %
L=2^6;
%
num=16; %
N=num*L % (1024)
Pf=0.01:4.836e-4:1
f0=16; %
dt=Ts/L %
df=1/(dt*N) %
Bs=df*N/2 %
fs=Bs*2
f=df/2-Bs:df:Bs; %
t=dt/2:dt:num*Ts; % t= 1/(4*64) : 1/(2*64) : 8;
a=sign(randn(1,num)); % generate the initial signal (length is 16)
%%%%%%%%%%%% BPSK
% function ?????????????????????????????????
for rr=1:num
I((rr-1)*L+1:rr*L)=a(rr); % number of I is 1024 .extend the length of signa
l 'a' to 64 times length.
end
figure(4);
plot(I)
% the signal modulated by BPSK carrier
s=I.*cos(2*pi*f0*t); % the number of 't'and 's' are the same.(1024)
figure(1);
plot(s);
axis([0 600 -1 1]); %look 35/1024 percent of the plot.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% begin to process the signal (look the .doc )
M=2; % ??????????????????????????
Fs=fs;
N = (M*Fs)/df; % the new value of 'N'is 2 times the value of old 'N'. (2048)
N = pow2 (nextpow2(N)); % windowing record for FFT (2048) % NEXTPOW2(N) return
s the first P such that 2^P >= abs(N)
% X = POW2(Y) for each ele
ment of Y is 2 raised to the power Y
%FFT1024
X = fft(s,N); % fft of the truncated() (or zero padded) time series (2048 columns)
X = fftshift(X);% shift components of fft (2048 columns)
Xc = conj(X);
% precompute the complex conjugate() vector (2048 column
s)
S = zeros (N,N);
f = zeros (N,N);
alfa = zeros (N,N);

% size of the Spectral Correlation Density matrix


% size of the frequency matrix;
% size of the cycle frequency matrix

F = Fs/(2*N);
% precompute() constants - F = Fs/(2*N);
G = Fs/N;
% precompute constants - G = Fs/N;
m = -M/2+1:M/2;
% set frequency smoothing window index % m(0)=0,m
(1)=1.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Algorithm:
for k = 1:N
% fix k
(2048 columns) % the funct
ion of fix is choose the integral value towards '0'.
% computes vectors of f and alfa,
% store frequency and cycle frequency data for given k.
i=0;
thresh(k) = (qfuncinv(Pf(k))./sqrt(l))+ 1;
k1 = 1:N;
f(k,k1) = F*(k+k1-1) - Fs/2;
% Computes f values and shift them to
center in zero (f = (K+L)/2N) [1]
alfa(k,k1) = G*(k-k1 + N-1) - Fs;
% Computes alfa values and shift the
m to center in zero (alfa = (K-L)/N) [1]
for k1 = 1:N
%fix k1 = J
%

%calculate X(K+m) & conj (X(J+m)) for arguments of X(1:N) only


thresh(k)=gammaincinv(1-Pf(k),0)*2;

B = max(1-k, 1-k1);
% Largest min of 1 <= (K+m)| (J+m) <= N
A = min (N-k, N-k1);
% Smallest max of 1 <= (K+m)| (J+m) <= N
n = m((m<=A) & (m>=B));
% fix the index out of range problem by
truncating the window. % m(0)=0,m(1)=1.
if isempty(n)
S(k,k1) = 0;
else
p = k+n; q = k1+n;
Y = X(p).*Xc(q);
S(k,k1) = sum(Y); % the power spetral Correlation density func
tion ??????????????????
end
if (S(k,k1) >= thresh(k))
i=i+1;
end
end
Pd(k)=i/k;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% haha=length(sign([real(Y)]))
S = abs(S./max(max(S)));% normalize output matrix
% figure(3);
% contour (alfa, f, S); grid;
figure(2);
f=zeros(N,N);
plot(alfa,S,'r'); % 'alfa'is cycle frequency.'f'is frequency.'S'is Spetral Corre
lation Density Function.
axis([-100 100 0 1]);
ylabel('Frequency (Hz)');xlabel('Cycle frequency (Hz)');
title('BPSK');
figure();
plot(S)
% for k=1:N
%
%
for kk=1:N
%

%
if S(kk) < thresh(k)
%
i=i+1;
%
end
%
end
%
Pd(k)=i/kk;
% end
% Pd_the = qfunc(((thresh - (snr + 1)).*sqrt(L))./(sqrt(2.*(snr + 1))));
figure();
plot(Pf,Pd,'r')%,Pf,Pd_the,'g')
hold on
toc

You might also like