www.pudn.com > tiaopin_maichongxinhao-.zip > test.m, change:2013-01-09,size:821b


clear; 
clc; 
fc=5e9; 
fs=25e9; 
R=0.001; 
t=-1.2:R:1.2;  
width=2; 
x=rectpuls(t,width); 
 
for i=1:length(x)   %采样点数目改变 (因为卷积的缘故) 
    t(i)=(i-1)/(fs);  %这里因为假设载频与码速率大小相等,所以用载频fc乘以过采样率=采样率。 
    Imod(i)=x(i)*sqrt(2)*cos(2*pi*fc*t(i)); 
    Qmod(i)=x(i)*(-sqrt(2)*sin(2*pi*fc*t(i))); 
end 
y=Imod+Qmod; 
%Imod1=x.*sqrt(2)*cos(2*pi*fc/fs*[0:2400]); 
%Qmod1=x.*(-sqrt(2)*sin(2*pi*fc/fs*[0:2400]); 
%y1=Imod1+Qmod1; 
%QPSK  receiver 
SNR=5; 
y=awgn(y,SNR,'measured'); 
L=4096; 
NFFT = 2^nextpow2(L); % Next power of 2 from length of y 
Y = fft(y,NFFT)/L; 
f = fs/2*linspace(0,1,NFFT/2+1); 
figure(1) 
plot(f,2*abs(Y(1:NFFT/2+1)))  
title('Single-Sided Amplitude Spectrum of y(t)') 
xlabel('Frequency (Hz)') 
ylabel('|Y(f)|') 
[z x]=max(2*abs(Y(1:NFFT/2+1))); 
fd=f(x); 
fc-fd