close all
clear all
clc
n=8; %阶次
p=2^n-1; %M序列周期;
ms1=idinput(p,'prbs');
ms=ms1(1:127);
n2=7; %阶次
p2=2^n2-1; %M序列周期;
ms2=idinput(p2,'prbs');
figure;
stairs(ms);
hold on;
stairs(ms2);
title('非线性M序列');
ylim([-1.5 1.5]);
grid on;
%M序列的性质验证;
disp('M序列的1和-1的个数:')
sum(ms1==1) %1的个数
sum(ms1==-1) %-1的个数,正常情况下,两者相差1;
disp('M序列的直流分量:')
mean(ms1) %M序列的直流分量,正常情况下长度很长时候,几乎等于0;
a1=zeros(length(ms)*10,1);
for i=1:10
a1(i:10:end)=ms;
end
a2=zeros(length(ms2)*10,1);
for i=1:10
a2(i:10:end)=ms2;
end
c1=xcorr(a1,'coeff'); %自相关函数计算;
figure;
plot(c1);
title('自相关函数'); grid on;
c2=xcorr(a1,a2);
figure;
plot(c2);
title('互相关函数'); grid on;
%功率谱密度;
figure;
pwelch(a2); title('功率谱密度')