matlab 程序调试

matlab 程序调试,第1张

%2FSK仿真程序

clear all

fs=2000

dt=1/fs

f1=20

f2=120

a=round(rand(1,10))

g1=a

g2= ~a

g11=(ones(1,2000))'*g1

g1a=g11(:)'

g21=(ones(1,2000))'*g2

g2a=g21(:)'

t=0:dt:10-dt

t1=length(t)

fsk1 =g1a.*cos(2*pi*f1.*t)%%%%%%%%%%%%%%%%%%%%%%%%%

fsk2 =g2a.*cos(2*pi*f2.*t)%%%%%%%%%%%%%%%%%%%%%%%%%

fsk=fsk1+fsk2 %产生的信号

no=0.0*randn

sn=fsk+no

subplot(311)plot(t,no)

subplot(312)plot(t,fsk)

% title(‘信号’)ylabel(‘’信号幅度)

subplot(313)plot(t,sn)

% title(‘叠加噪声后的信号’);ylabel(‘幅度A’)xlabel(‘时间t’)

figure(2)

b1=fir1(101,[10/80020/800])

b2=fir1(101,[90/800110/800])

H1=filter(b1,1,sn)H2=filter(b2,1,sn)

subplot(211)plot(t,H1)

% title(‘经过带通滤波器后f1的波形’)ylabel(‘幅度’)

subplot(212)plot(t,H2)

% title(‘经过带通滤波器后f2的波形’)ylabel(‘幅度’)xlabel(‘t’)

sw1=H1.*H1

sw2=H2.*H2

figure(3)

subplot(211)plot(t,sw1)

% title(‘经过相乘器h1后的波形’)ylabel(‘幅度’)

subplot(212)plot(t,sw2)

% title(‘经过相乘器h2后氏颂的波形’)ylabel(‘?幅度’)xlabel(‘t’)

bn=fir1(101,[2/80010/800])

figure(4)

st1=filter(bn,1,sw1)st2=filter(bn,1,sw2)

subplot(211)plot(t,st1)

% title(‘经过低通滤波器sw1后的波形’)ylabel(‘幅度’)

subplot(212)plot(t,st2)

% title(‘经过低通滤波器sw2后的波形’)ylabel(‘幅度’)xlabel(‘t’)

%判决

for(i=1:length(t))

if(st1(i)>=st2(i))st(i)=0

else st(i)=st2(i)

end

end

figure(5)

subplot(211)plot(t,st)

% title(‘经过抽样判决器后的波形’)ylabel(‘幅度’)

subplot(212)plot(t,sn)

% title(‘原始的波形’)ylabel(‘幅度’银汪)xlabel(‘t’)

%加入噪声后

no=0.3*randn(1,t1)

sn=fsk+no

figure(6)

subplot(311)plot(t,no)

title('噪声波形')ylabel('噪声幅度') %噪声波形

subplot(312)plot(t,fsk)

title('信号')ylabel('信号幅度')

subplot(313)plot(t,sn)

title('叠加有噪声的信号')ylabel('幅度A')xlabel('时间t')

figure(7)

b1=fir1(101,[10/800 20/800])

b2=fir1(101,[90/800 110/800]) %设置带通参数

H1=filter(b1,1,sn)H2=filter(b2,1,sn) %经过带通滤波器后的信号

subplot(211)plot(t,H1)

title('经歼搏郑过带通滤波器后f1的波形')ylabel('幅度')

subplot(212)plot(t,H2)

title('经过带通滤波器后f2的波形')ylabel('幅度')xlabel('t')

sw1=H1.*H1sw2=H2.*H2 %经过相乘器

figure(8)

plot(t,sw2)

title('经过相乘器后h2的波形')ylabel('?幅度')xlabel('t')

bn=fir1(101,[2/800 10/800]) %经过低通滤波器

figure(9)

st1=filter(bn,1,sw1)st2=filter(bn,1,sw2)

plot(t,st1)

title('经过低通滤波器sw1后的波形')ylabel('幅度')xlabel('t')

%判决

for i=1:length(t)

if(st1(i)>=st2(i))

st1(i)=0

else st1(i)=st2(i)

end

end

figure(10)

subplot(211)plot(t,st)title('经过抽样判决后的波形')ylabel('幅度')

subplot(212)plot(t,sn)title('原始波形')ylabel('幅度')xlabel('t')

%程序完

具体 *** 作步骤如下:

1、首先,打开Matlab软件,单击物冲[打扰败开]或创建一个新的调试文件,如下图所示,然后进入下一步。

2、其次,单击代码前面的横杠设置断点,如下图所示,然后进入下一步。

3、接着,单击[run],如下图所示,然后进入下一步。

4、然后,光标缓蚂颤停在该版本的断点处,然后按[F10]逐步执行,如下图所示,然后进入下一步。

5、最后,将光标放在要观察的变量上,停留一段时间,以查看变量值,再按F5执行完成,如下图所示。这样,问题就解决了。

 


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12305989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存