目錄
1、工具箱中常見的函數
(1)sawtooth函數
sawtooth函數用於產生鋸齒波或三角波信號,格式如下:
x=sawtooth(t),產生週期爲,幅值-1—1的鋸齒波,在的整數倍取值爲1或-1。斜率爲。
sawtooth(t,width),產生三角波,width介於0到1。
t=0:0.0001:1;
y=sawtooth(2*pi*50*t);
subplot(211);
plot(t,y)
axis([0,0.2,-1,1]);
y1=sawtooth(2*pi*50*t,0.5);
subplot(212);
plot(t,y1)
axis([0,0.2,-1,1]);
(2) square函數
square函數用於產生方波信號,調用格式爲:
x=square(t),產生週期爲,幅值爲-1到1。
x=square(t,duty),產生指定的週期信號,duty爲正半週期所佔比例。
t=0:0.0001:1;
y1=square(2*pi*50*t);
subplot(211);
plot(t,y1)
axis([0,0.2,-2,2]);
xlabel('方波信號');
y2=square(2*pi*50*t,70);
subplot(212);
plot(t,y2)
axis([0,0.2,-2,2]);
xlabel('正半週期所佔比例爲70%');
(3) sinc函數
sinc函數表示爲:,其調用格式爲:y=sinc(t)。
x=linspace(-4,4,200);
y=sinc(x);
plot(x,y)
(4)rectpuls函數
rectpuls函數用於產生非週期方波信號,調用格式:
y=rectpuls(t), y=rectpuls(t,w),產生指定寬度爲w的非週期方波。
t=0:0.01:2;
y1=rectpuls(t);%默認0.5
subplot(211);
plot(t,y1)
axis([0,2,-2,2]);
y2=rectpuls(t,0.8);%0.4處
subplot(212);
plot(t,y2);
axis([0,2,-2,2]);
(5)tripuls函數
tripuls用於產生非週期三角波信號,格式:
y=tripuls(t,w,s),產生指定寬度爲w的非週期三角波,斜率爲s(-1—1)。
t=-1:0.01:1;
y=tripuls(t,1,-1);
plot(t,y)
axis([-1,1,-2,2]);
(6)chirp函數
chirp函數用於產生線性調頻掃頻信號,格式:
y=chirp(t,f0,t1,f1),產生一個線掃頻信號。(默認值:f0=0HZ,t1=1,f1=100HZ)。
y=chirp(t,f0,t1,f1,'method'),method爲調頻方法有:linear(線性)、quadratic(二次)、logarithmic(對數),默認線性。
t=0:0.01:1;
y=chirp(t,0,1,200);
plot(t,y)
axis([0,1,-1,1]);
(7)pulstran函數
pulstran用於產生衝擊串函數,格式:
y=pulstran(t,d,'func'),指定時間範圍t,位移d,連續函數func。
t=0:0.001:1;
d=0:0.25:1;
y=pulstran(t,d,'square');
plot(t,y)
(8) diric函數
diric函數用於產生Dirichelt信號,格式:
y=diric(x,n),用於產生x的Dirichelt函數。
x=0:10;
y=diric(x,3);
plot(x,y)
(9) gauspuls函數
gauspuls函數用於產生高斯正弦脈衝信號,格式:
y=gauspuls(t,fc,bw,bwr),返回持續時間t,中心頻率fc,帶寬bw。幅度爲1的高斯正弦脈衝信號的抽樣。
tc=gauspuls('cutoff',fc,bw,bwr,tpe),返回值按照參數tpe計算所對應的截斷時間tc。
例:產生頻率爲60KHZ,寬度爲80%的高斯RF脈衝信號,要求脈衝包絡下降到60dB(默認值)截斷。
tc=gauspuls('cutoff',60000,0.8,[ ],-60);
t=-tc:0.000000001:tc;
y=gauspuls(t,60000,0.8);
plot(t,y)
(10) gmonopuls函數和vco函數
gmonopuls函數用於產生高斯單脈衝信號,vco函數時電壓控制震盪函數。
2、離散信號表示
(1)離散信號
如果表示爲:x(2)=-2,x(1)=1,x(0)=3,x(-1)=4,x(-2)=6,1其餘爲0。
t=-3:3;
x=[0 6 4 3 1 -2 0];
stem(t,x)
grid
(2) 單位脈衝序列
x=zeros(1,6);
x(1,2)=1;
n=0:5;
stem(n,x)
(3)單位階躍序列
n=[-11:11];
x=[(n-3)>=0];
stem(n,x)
(4)實指數序列
n=1:11;
x=2.^n;
stem(n,x)
(5) 復指數序列
n=1:10;
x=exp((1+j).*n);
subplot(211);
stem(n,real(x))
subplot(212);
stem(n,imag(x))
(6)正(餘)弦序列
n=1:0.1:10;
x=cos(0.5*pi.*n);
stem(n,x)