[SCILAB]信号与系统实验1-绘制连续时间信号图片

信号与系统实验一:连续时间信号的scilab表示

环境信息:SCILAB 6.1.1
安装插件:Scilab support for Visual Studio Code(mammothb)
安装工具箱:Scilab Wavelet Toolbox

实验目的

  1. 熟悉典型信号的波形和特性。
  2. 熟悉 SCILAB 的运行环境,学会使用 SCILAB 表示连续时间信号的方法。
  3. 观察并熟悉典型信号的波形和特性。

MATLAB与SCILAB函数对比

MATLAB SCILAB
axis mtlb_axis
plot plot
plot2d plot2d
xlabel xlabel
ylabel ylabel
title title
pi %pi
i %i
image imag
real real
angle(A) atan(imag(A),real(A))
abs abs
sign sign
grid on xgrid或target.grid = [1 1 1];
grid off gca().grid = -[1 1 1];
sinc sinc
size size
ones ones
and and

[例1-1]描述单边衰滅指数信号

//[例1-1]描述单边衰滅指数信号
k=4;
a=-3;
//横轴
t=0:.01:3;
f=k*exp(a*t);
plot(t,f);
//调整横纵坐标范围
mtlb_axis([0 3 0 5]);
title("单边指数信号");
xlabel("时间(t)");
ylabel("f(t)");

k=4;
a=-3;
t=0:.01:3;
f=k*exp(a*t);
plot(t,f);
axis([0 3 0 5]);
title('单边指数信号')
xlabel('时间(t)');
ylabel('f(t)');

[例1-2]描述正弦信号

//[例1-2]描述正弦信号
k=3;
w=2;
phi=%pi/3;
t=0:.01:5;
f=k*sin(w*t+phi);
plot(t,f);
mtlb_axis([0 5 -4 4]);
title("正弦信号");
xlabel("时间(t)");
ylabel("f(t)");

k=3;
w=2;
phi=pi/3;
t=0:.01:5;
f=k*sin(w*t+phi);
plot(t,f);
axis([0 5 -4 4]);
title('正弦信号');
xlabel('时间(t)');
ylabel('f(t)');

[例1-3]描述复指数信号

//[例1-3]描述复指数信号
t=0:.01:3;
k=2;
a=-3;
b=4;
f=k*exp((a+b*%i)*t);
//第一张图
subplot(2,2,1);
plot(t,real(f));
title("实部");
xlabel("时间(t)");
//第二张图
subplot(2,2,2);
plot(t,imag(f));
title("虚部");
xlabel("时间(t)");
//第三张图
subplot(2,2,3);
plot(t,abs(f));
title("模");
xlabel("时间(t)");
//第四张图
subplot(2,2,4);
plot(t,atan(imag(f)),real(f));
title("相角");
xlabel("时间(t)");

t=0:.01:3;
k=2;
a=-3;
b=4;
f=k*exp((a+b*i)*t);
%%第一张图
subplot(2,2,1);
plot(t,real(f));
title("实部");
xlabel("时间(t)");
%%第二张图
subplot(2,2,2);
plot(t,image(f));
title("虚部");
xlabel("时间(t)");
%%第三张图
subplot(2,2,3);
plot(t,abs(f));
title("模");
xlabel("时间(t)");
%%第四张图
subplot(2,2,4);
plot(t,angle(f));
title("相角");
xlabel("时间(t)");

[例1-4]描述单位斜变信号

//[例1-4]描述单位斜变信号
t=0:.01:3;
k=2;
f=k*t;
plot(t,f);
title("斜变信号");
xlabel("时间(t)");
ylabel("f(t)");

%%[例1-4]描述单位斜变信号
t=0:.01:3;
k=2;
f=k*t;
plot(t,f);
title("斜变信号");
xlabel("时间(t)");
ylabel("f(t)");

[例1-5]描述单位阶跃信号(失败)

//[例1-5]描述单位阶跃信号
t=-1:.01:4;
function y=f(x)
    if x>=0 then
        disp("t>=0");
        y=1;
        //f=1;
    elseif x<0 then
        disp("t<0");
        y=-1;
        //f=-1;
    end
endfunction
plot(t,f(t));
mtlb_axis([-2 5 -1 2]);
title("单位阶跃信号");
xlabel("时间(t)");
ylabel("u(t)");


期望结果:

[例1-6]描述符号函数信号

//[例1-6]描述符号函数信号
t=-5:.01:5;
f=sign(t);
plot(t,f);
mtlb_axis([-2 5 -2 2]);
title("符号函数");
xlabel("时间(t)");
ylabel("sgn(t)");

%%[例1-6]描述符号函数信号
t=-5:.01:5;
f=sign(t);
plot(t,f);
axis([-2 5 -2 2]);
title("符号函数");
xlabel("时间(t)");
ylabel("sgn(t)");

[例1-7]描述抽样信号

//[例1-7]描述抽样信号
t=2*%pi:.01:2*%pi;
f=sinc(t);
mtlb_axis([-8 8 -0.5 1.2]);
plot(t,real(f));
title("抽样信号");
xlabel("时间(t)");
target.grid =[1 1 1];//grid on


期望结果:

另一种:

//Resampling a signal using intdec
dt=.001;
t=(0:999)*dt;
f=sin(%pi*t).*sin(16*%pi*t);
g=intdec(f,2/5);
xsetech([0,0,1,.5]);
plot(f);
xtitle("信号在1000Hz采样频率");
xsetech([0,0.5,1,.5]);
plot(g);
xtitle("信号在400Hz采样频率");

另一种:

t = linspace(-10,10,1000);
y = rc_pulse(t,0.5);
clf(); plot(t,y);

[例1-8]描述矩形脉冲信号(失败)

//[例1-8]描述矩形脉冲信号
function y=rectpuls(x)
    if x>=0 then
        disp("t>=0");
        y=1;
        //f=1;
    elseif x<0 then
        disp("t<0");
        y=-1;
        //f=-1;
    end
endfunction
t=-2:.01:5;
T=2;
f=rectpuls(t)-rectpuls(t-T);
plot2d(t,f);
mtlb_axis([-1.5 -1 2]);
title("矩形脉冲信号");
xlabel("时间(t)");
ylabel("f(t)");


期望结果:

[例1-9]产生周期矩形脉冲信号(失败)

//[例1-9]产生周期矩形脉冲信号
//SCILAB没有square函数
t=-2:.01:2;
f=square(2*%pi*t,30);
plot(t,f);
mtlb_axis([-2 2 -1.5 1.5]);
title("周期矩形脉冲信号");
xlabel("时间(t)");
ylabel("f(t)");
xgrid//grid on


期望结果:

[例1-10]产生非周期三角脉冲信号(失败)

//[例1-10]产生非周期三角脉冲信号
t=2:.01:2;
//SCILAB没有tripuls函数
f=tripuls(t,2,0.5);
plot(t,f);
mtlb_axis([-2 2 -0.5 1.5]);
title("三角脉冲信号");
xlabel("时间(t)");
ylabel("f(t)");
xgrid//grid on


期望结果:

[例1-11]产生周期直角三角脉冲信号(失败)

//[例1-11]产生周期直角三角脉冲信号
t=-8:.01:8;
f=sawtooth(t*%pi,0);//SCILAB没有sawtooth锯齿波函数
plot(t,f);
mtlb_axis([-8 8 -1.5 1.5]);
title("周期三角脉冲信号");
xlabel("时间(t)");
ylabel("f(t)");
xgrid//grid on


期望结果:

附录:原题(MATLAB版)








posted @ 2023-02-25 21:35  qsBye  阅读(207)  评论(0编辑  收藏  举报