www.gusucode.com > 认知无线电频谱检测技术的研究,有循环检测,周期性检测源码程序 > 程序/zhouqi.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成bpsk调制信号 fs=100; %采样频率 fc=40; %载频 fo=fs/20; %码率 a=2*fo; %循环周期 T=40; %信号样本 x=rand(40,1); y=round(x); a1=y*2-1; z=ones(200,1); for i=1:40 for j=1:5 an(5*i-5+j)=z(5*i-5+j)*a1(i); end end t=1/fs:1/fs:2; xn=an.*cos(4*pi*fc*t); figure(1) plot(t,xn); axis([0 2 -1.5 1.5]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%进行周期图检测 window=kaiser(length(xn),0.5); %矩形窗 nfft=512; %512fft [Pxx,f]=periodogram(xn,window,nfft,fs); %周期图检测 %%%%%%%%%(生成一段加噪信号) as=rand(20,1); b=as*2; c=floor(b); d=reshape(c,10,2); e=bi2de(d,'left-msb'); h=modem.qammod(4); g=modulate(h,e); scatterplot(g); %生成一段随机4QAM信号 N=length(g); x=real(g); y=imag(g); fc=40; %载波频率,有线电视信号 t0=0.000001; ts=1e-010; t1=0:ts:t0; n1=0.1*randn(1,N); for i=1:N s1=x(i)*cos(2*pi*fc*t1)-y(i)*sin(2*pi*fc*t1); end %生成4QAM调制后信号 %加入噪声nt t2=0.000001:1e-010:0.000002; M1=length(t2); nt=0.1*randn(1,M1); s2=nt.*cos(2*pi*fc*t2); %add nt t=0:ts:0.000002; s=zeros(1,20001); for i=1:10001 s(i)=s1(i); end for j=1:10000 s(j+10000)=s2(j); end %加入间隔无信号时间 %生成调制后信号 %%%%%%%%%%%%%%%%%%%%%%(1)取有用信号时间段,计算函数值 cl=xcorr(s1); L=length(cl); i2=1:2:L; c2=cl(i2); %自相关函数 a1=fc; %循环周期 %构造积分对象pp p=exp(-2*pi*t1*j); M=length(p); pp=c2.*p; %进行无穷大积分 ts=1e-010; cxx1=pp*ts; u1=sum(cxx1(1:10),'double'); %加入统计频率周期a2 N1=length(c2); N2=length(t); f1=60e6; %采样时间 Te=0.03; i3=1:N1; a2=i3./(N1*Te); tj1=exp(a2); cx1=tj1*u1*1e10; U1=sum(cx1(1:10)); %%%%%%%%%%%%%%%%%%%%%%(2)取噪声时间段,计算函数值 cl2=xcorr(s2); L=length(cl2); i3=1:2:L; c22=cl2(i3); p2=exp(-2*pi*t2*j); M2=length(p); pp2=c22.*p2; %进行无穷大积分 ts=1e-010; cxx2=pp2*ts; u2=sum(cxx2(1:10),'double'); %加入统计频率周期a2 i3=1:N1; a2=i3./(N1*Te); tj2=exp(a2); cx2=tj2*u2*1e10; U2=sum(cx2(1:10)); %检测完毕 %%%%%%%%%%%%%%%%%%% 输出检测示意图; tz=0:ts:0.000002; sz=zeros(1,20001); for i=1:10001 sz(i)=U1; end for j=1:10000 sz(j+10000)=U2; end %%%%%%%%(检测完成,输出图谱) figure(2) plot(f,-10*log10(Pxx)); window=kaiser(length(xn),0.5); nfft=1024; %%%%%%%%%%%%%%%%%%%%%%%%%%%%1024fft [Pxx,f]=periodogram(xn,window,nfft,fs); %周期图检测 figure(3) plot(f,-10*log10(Pxx)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%对不同类型窗函数进行检测性能分析 window1=boxcar(length(xn)); %矩形窗 window2=hamming(length(xn)); %海明窗 window3=blackman(length(xn)); %blackman窗 [Pxx1,f]=periodogram(xn,window1,nfft,fs); [Pxx2,f]=periodogram(xn,window2,nfft,fs); [Pxx3,f]=periodogram(xn,window3,nfft,fs); figure(4) subplot(221) plot(f,-10*log10(Pxx)); subplot(222) plot(f,-10*log10(Pxx1)); subplot(223) plot(f,-10*log10(Pxx2)); subplot(224) plot(f,-10*log10(Pxx3));