仿真信号建立 ,输入信号和本振同频不同相,混频后的实现和量化.
%SimSigproduce.m
%set system parameters
fi=625000;
fc=625000;
Fs=5000000;
L=1024;
N=10;
%generate input signal
t=0:1/Fs:1/Fs*(L-1);
theta=rand()*2*pi;
si=sin(2*pi*fi*t+theta);
si=round(si*(2^(N-1)-1));
%generate LO Signal
sc=sin(2*pi*fc*t);
sc=round(sc*(2^(N-1)-1));
%sim mix input and plot
so=si.*sc;
sof=so-mean(so);
fso=abs(fft(so,L));
%
sc=sc/max(abs(sc));
si=si/max(abs(si));
so=so/max(abs(so));
sof=sof/max(abs(sof));
fso=fso/max(fso);
%
fso=[fso(L/2+1:L),fso(1:L/2)];
m=[-L/2:1:(L/2-1)]*Fs/L*(10^(-6));
t=t*(10^6);
subplot(221),plot(t(1:32),si(1:32)),title('10bit quantization','fontsize',8);
subplot(222),plot(t(1:32),so(1:32)),title('20bit quantization','fontsize',8);
subplot(223),plot(t(1:32),sof(1:32)),title('mixer filter the dc pon','fontsize',8);
subplot(224),plot(m,fso),title('mixer output signal H(w)','fontsize',8);
f_s=si/max(abs(si));
Q_s=round(f_s*(2^(N-1)-1));
%******************************%
%
%????Error using ==>fprintf
%Invalid file identifiter
fid=fopen('F:\matlab\Digital_Filter\01\SinIn.txt','w');
for k=1:length(Q_s)
B_s=dec2bin(Q_s(k)+(Q_s(k)<0)*2^N,N);
for j=1:N
if B_s(j)=='1'
tb=1;
else
tb=0;
end
fprintf(fid,'%d',tb);
end
fprintf(fid,'\r\n');
end
fprintf(fid,';');
fclose(fid);