BPSK循环谱
现有程序需要优化改错
现在的问题主要有以下几个:
1. 程序运行速度慢
2. 有一个参数M,在M取2,4时,均能运行得到正确的结果,但是当M取8以上时,运行出错,并且M值取不同的时候程序的错误不同,具体的你可以试试。
你的主要任务,是将错误产生的原因找出来并改正,错误消除了以后再进行程序的进一步优化工作。
谢谢各位达人了...
%数据设置部分
Rb=2; %码源速率
Ts=1/Rb; %码源间隔
L=2^6; %单位时间内信号抽样点数
num=16; %一个段落中码源个数
N=num*L; %一个段落内总的抽样点数
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; %抽样时间
a=sign(randn(1,num)); %码源序列
%BPSK调制信号产生
%通过基带成型滤波器后的信号
for rr=1:num
I((rr-1)*L+1:rr*L)=a(rr);
end
%最终调制信号
s=I.*cos(2*pi*f0*t);
M=2;
Fs=fs;
N = (M*Fs)/df;
N = pow2 (nextpow2(N)); % windowing record for FFT
%N=; %设置FFT点数为1024
X = fft(s,N); % fft of the truncated (or zero padded) time series
X = fftshift(X);% shift components of fft
Xc = conj(X); % precompute the complex conjugate vector
S = zeros (N,N); % size of the Spectral Correlation Density matrix
f = zeros (N,N); % size of the frequency matrix;
alfa = zeros (N,N); % 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
for k = 1:N % fix k
% computes vectors of f and alfa,
% store frequency and cycle frequency data for given k.
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 them 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
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
if isempty(n)
S(k,k1) = 0;
else
p = k+n; q = k1+n;
Y = X(p).*Xc(q);
S(k,k1) = sum(Y);
end
end
end
S = abs(S./max(max(S)));% normalize output matrix
% figure(1);
% contour (alfa, f, S); grid;
figure(1);
mesh(alfa, f, S);
ylabel('Frequency (Hz)');xlabel('Cycle frequency (Hz)');
title('BPSK循环谱三维图');