MATLAB基本信号的产生

版权声明:本文为博主原创文章,如需转载,请注明出处 https://blog.csdn.net/qq_36554582/article/details/83187658

1、随机信号:rand

%随机函数
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

%三角波函数
%格式一: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

%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

%线性调频函数
%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

%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

%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

%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

%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

%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

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_36554582/article/details/83187658