1、随机信号:rand
复制代码
1
2
3
4
5
6
7
8
9
10
11%随机函数 tn=0:40;%设定随机信号的长度 N=length(tn);%求出序列tn的长度 x=rand(1,N);%产生一维的、长度为N的随机信号 subplot(121) plot(tn,x,'k');%绘制函数x的图形 ylabel('x(t)') subplot(122) stem(tn,x,'filled','k');%绘制火柴梗图(茎状图) ylabel('x(n)')
2、三角波信号:sawtooth
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18%三角波函数 %格式一:x=sawtooth(t) %功能:产生周期为2pi,振幅为-1~1的锯齿波。在2pi的整数倍处值为-1~1,这一段波形斜率为1/pi %格式二:sawtootn(x,width) %功能:产生三角波,width在0到1之间 clear all; f=50;%设定三角波的频率,50Hz,即周期为0.02 fs=10000; t=0:1/fs:1; x1=sawtooth(2*pi*f*t,0);%绘制三角波,参数0表示锯齿向左倾斜 x2=sawtooth(2*pi*f*t,1);%绘制三角波,参数1表示锯齿向右倾斜 subplot(211) plot(t,x1); axis([0 0.2 -1 1]); subplot(212) plot(t,x2); axis([0 0.2 -1 1])
3、sinc信号:sinc
复制代码
1
2
3
4
5
6
7
8
9
10
11
12%sinc函数 %sinc函数定义为:sinc(t)=sin(t)/t clear all t=(1:12)'; x=randn(size(t)); ts=linspace(-5,15,600)'; y=sinc(ts(:,ones(size(t)))-t(:,ones(size(ts)))')*x; plot(t,x,'o',ts,y); ylabel('x(n)') xlabel('n') grid on
4、线性调频信号:chirp
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25%线性调频函数 %y=chirp(t,f0,t1,f1) %功能:产生一个线性(频率随时间线性变化)信号,其时间轴设置由数组t定义。时刻0的瞬间频率为f0,时刻t1的瞬间频率为f1 %默认情况下:f0=0Hz,t1=1,f1=100Hz %y=chirp(t,f0,t1,f1,'method') %功能:指定改变扫频的方法。可用的方法有'linear'(线性扫频)、'quadratic'(二次扫频)和'logarithmic'(对数扫频) %默认情况下:'linear'。 %注意:对于对数扫频,必须有f1>f0。 %y=chirp(t,f0,t1,f1,'method',phi) %功能:指定信号的初始相位为phi(单位为度) %默认情况下:phi=0 %y=chirp(t,f0,t1,f1,'quadratic',phi,'shape') %功能:根据指定的方法(在这里就为二次扫频)在时间t上产生余弦扫频信号,时刻0的瞬间频率为f0,时刻t1的瞬间频率为f1,单位都是Hz %默认情况下:f0默认为e-6(对数扫频方法)或0(其他扫频方法),t1为1,f1为100Hz %shape指定耳聪扫频方法的抛物线的形状是凹还是凸,值为concave或convex,如果此信号被忽略,则根据f0和f1的相对大小决定是凹还是凸 clear all t=0:0.01:2; y=chirp(t,0,1,150); plot(t,y) axis([0 0.5 0 1]) ylabel('x(t)') xlabel('t') grid on
5、diric信号:diric
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18%diric函数 %y=diric(x,n) clear all t=-4*pi:pi/20:4*pi; subplot(211) plot(t,sinc(t));%绘制sinc函数 title('Sinc'); grid on xlabel('t') ylabel('sinc(t)') subplot(212) plot(t,diric(t,5));%绘制diric函数 title('Diric') grid on xlabel('t') ylabel('diric(t)')
6、非周期方波信号:rectpuls
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21%rectpuls函数 %功能:产生非周期方波信号 %y=rectpuls(t),默认方波的宽度为1 %y=rectpuls(t,w),产生指定宽度为w的非周期方波 clear all t=-2:0.001:2; y=rectpuls(t); subplot(121) plot(t,y); axis([-2 2 -1 2]) grid on xlabel('t') ylabel('h(t)') y=2*rectpuls(t,2); subplot(122) plot(t,y); grid on axis([-2 2 -1 3]) grid on
7、非周期三角波信号:tripuls
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16%tripuls函数 %功能:产生非周期三角波信号函数tripuls %y=tripuls(t) %y=tripuls(t,w) %y=tripuls(t,w,s) 产生周期为w的非周期三角波,斜率为s(-1<s<1) clear all t=-3:0.001:3; y=tripuls(t,4,0.5); plot(t,y) grid on axis([-3 3 -1 2]) grid on xlabel('t') ylabel('h(t)')
8、脉冲序列发生器:pulstran
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29%pulstran函数 %功能:脉冲序列发生器 %y=pulstran(t,d,'func') %该函数基于一个名为func的连续函数并以之为一个周期,从而产生一串周期性的连续函数(func函数可自定义) %该pulstran函数的横坐标范围由向量t指定,而向量d用于指定周期性的偏移量(即各个周期的中心点),这样一个func函数会被计算length(d)次, %从而实现一个周期性脉冲信号的产生 %y=pulstran(t,d,'func',p1,p2,...) %其中的p1,p2,...为需要转送给func函数的额外输入参数值(除了变量t之外) clear all T=0:1/1E3:1; D=0:1/4:1; Y=pulstran(T,D,'rectpuls',0.1);%生成周期性的矩形脉冲信号 subplot(121) plot(T,Y) xlabel('t') ylabel('h(t)') grid on axis([0 1 -0.1 1.1]) T=0:1/1E3:1; D=0:1/3:1; Y=pulstran(T,D,'tripuls',0.2,1);%生成周期性的三角波信号 subplot(122) plot(T,Y) xlabel('t') ylabel('h(t)') grid on axis([0 1 -0.1 1.1])
9、高斯信号:gauspuls
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16%gauspuls函数 %功能:产生高斯正弦脉冲信号 %yi=gauspuls(t,fc,bw) %yi=gauspuls(t,fc,bw,bwr) %[yi,yq]=gauspuls(...) %tc=gauspuls('cutoff',fc,bw,bwr,tpe) clear all tc=gauspuls('cutoff',50e3,0.6,[],-40); t=-tc:1e-6:tc; yi=gauspuls(t,50e3,0.6); plot(t,yi); xlabel('t') ylabel('h(t)') grid on
最后
以上就是自然冰棍最近收集整理的关于MATLAB基本信号的产生的全部内容,更多相关MATLAB基本信号内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复