function work_2
%%%%为了方便看波形 建一个窗口 实现点一下鼠标换个波形
handles.figure = figure ('unit','normalized','position',[0.07,0.07,0.85,0.85],...
'WindowButtonDownFcn',@Draw);
%%%%%%%
%%%%%%
handles.flag = 1;
handles.flagMax = 7;
fc = 1000 ; %载波频率
fs = 10000; %采样频率
f0 = 100; %码元速率
N = 100;
bits = [];sig = [];z = [];
SNR = 10;
t = 0 : 1/fs : 10*(1/fs)*100 - (1/fs);
%%%%%%%%%
%%%%%%%%%%%每个码元对应10个载波周期、每个载波周期采样10个点
%%%%%%%%%每个码元周期采样100个点
function Draw(t1,t2)
flag = handles.flag;
if(flag == 1)
%数字信号
%%%%%%%%%%
bit = [0 1 1 0 1 1 0 0 1 0]; %10个数字信号
for i = 1 : length(bit)
if bit(i) == 0
bits = zeros(1,N);
else bits = ones(1,N);
end
sig = [sig,bits];
end
subplot(2,1,1);plot(sig);
axis([0,1000,-0.5 ,1.5]);
title('信号波形');
xlabel('t');
[Pxx,Pxxc,f] = pmtm(sig,3.5,1024,fs,0.99);
hpsd = dspdata.psd(Pxx,'Fs',fs);
subplot(2,1,2);plot(hpsd);
title('信号波形频谱');
xlabel('t');
%%%%%%%%%%%%%%%%%%%
end;
if(flag == 2)
%调制信号
%%%%%%%%%%%%%%%
c = cos(2*pi*fc*t);
z = [z,c];
handles.y0 = z.*sig;
subplot(2,1,1);plot(t,handles.y0);
axis([0 100*(1/fc) -1.5 1.5]);
title('调制信号波形');
xlabel('t');
[Pxx,Pxxc,f] = pmtm(handles.y0,3.5,1024,fs,0.99);
hpsd = dspdata.psd(Pxx,'Fs',fs);
subplot(2,1,2);plot(hpsd);
title('调制信号波形频谱');
xlabel('t');
%%%%%%%%%%%%%%%%%%%
end;
if(flag == 3)
%添加噪声
%%%%%%%%%%%%%%%%
handles.y1 = awgn(handles.y0,SNR,'measured');
subplot(2,1,1);plot(t,handles.y1);
axis([0 100*(1/fc) -1.5 1.5]);
title('加噪声后的调制信号波形');
xlabel('t');
[Pxx,Pxxc,f] = pmtm(handles.y1,3.5,1024,fs,0.99);
hpsd = dspdata.psd(Pxx,'Fs',fs);
subplot(2,1,2);plot(hpsd);
title('加噪声后调制信号波形频谱');
xlabel('t');
%%%%%%%%%%%
end;
if(flag == 4)
%带通滤波
Wp = [800 1200]/(fs/2);
Rp = 0.1;
Rs = 10;
[b,a] = ellip(4,Rp,Rs,Wp);
handles.y2 = filter(b,a,handles.y1);
subplot(2,1,1);plot(t,handles.y2);
axis([0 100*(1/fc) -1.5 1.5]);
title('带通滤波后的调制信号波形');
xlabel('t');
[Pxx,Pxxc,f] = pmtm(handles.y2,3.5,1024,fs,0.99);
hpsd = dspdata.psd(Pxx,'Fs',fs);
subplot(2,1,2);plot(hpsd);
title('带通滤波后的调制信号波形频谱');
xlabel('t');
%%%%%
end;
if(flag == 5)
%解调
%%%%%%%%
handles.y3 = handles.y2 .*cos(2*pi*fc*t);
subplot(2,1,1);plot(t,handles.y3);
axis([0 100*(1/fc) -1.5 1.5]);
title('解调后的信号波形');
xlabel('t');
[Pxx,Pxxc,f] = pmtm(handles.y3,3.5,1024,fs,0.99);
hpsd = dspdata.psd(Pxx,'Fs',fs);
subplot(2,1,2);plot(hpsd);
title('解调后的信号波形频谱');
xlabel('t');
%%%%%%%%%
end;
if(flag == 6)
%低通滤波
Wp = 950/(fs/2);
Rp = 0.1;
Rs = 10;
[b,a] = ellip(4,Rp,Rs,Wp);
handles.y4 = filter(b,a,handles.y3);
subplot(2,1,1);plot(t,handles.y4);
axis([0 100*(1/fc) -1.5 1.5]);
title('低通滤波后的解调信号波形');
xlabel('t');
[Pxx,Pxxc,f] = pmtm(handles.y4,3.5,1024,fs,0.99);
hpsd = dspdata.psd(Pxx,'Fs',fs);
subplot(2,1,2);plot(hpsd);
title('低通滤波后的解调信号波形频谱');
xlabel('t');
%%%%%
end;
if(flag == 7)
%抽样判决、硬判决
%%%%%%%%%%%%
BITS = [];SIG = [];Z = [];
t = f0/2; %
for i = 1 : 10 %%%%%判决电平
if(handles.y4(t) > 0.5) Z(i) = 1; %%%%%取0.5为判决电平
else Z(i) = 0;
end
t = t + f0;
end
for i = 1 : length(Z)
if Z(i) == 0
BITS = zeros(1,N);
else BITS = ones(1,N);
end
SIG = [SIG,BITS];
end
subplot(2,1,1);plot(SIG);
axis([0,1000,-0.5 ,1.5]);
title('硬判决后的信号波形');
xlabel('t');
[Pxx,Pxxc,f] = pmtm(SIG,3.5,1024,fs,0.99);
hpsd = dspdata.psd(Pxx,'Fs',fs);
subplot(2,1,2);plot(hpsd);
title('硬判决后的信号波形频谱');
xlabel('t');
%%%%%%%%%%
end;
if(handles.flag < handles.flagMax)
handles.flag = handles.flag + 1;
end ;
end
end
评论0