目录
1.序列相加与相乘:
信号相加(相乘)是对信号值之间的相加(相乘),实现语句为
x=x1+x2;
x=x1.*x2;
注意:①相加和相乘的前提是参加运算的两个信号的长度必须相同;
②相乘注意要使用点乘(.*)。
%序列相加
clc;clear all;close all;
n1=0:3;
x1=[1.5 0.7 0.4 1];
subplot(311);
stem(n1,x1);
axis([-1 9 0 1.6]);
n2=0:7;
x2=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7];
subplot(312);
stem(n2,x2);axis([-1 9 0 0.9]);
n=0:7;
x1=[x1 zeros(1,8-length(n1))];
x2=[zeros(1,8-length(n2)) x2]; %这里length(n2)即求n2的长度,结果为8
x=x1+x2;
subplot(313);
stem(n,x);axis([-1 9 0 2.1]);
%序列相乘
clc;clear;close all;
n1=0:3;
x1=[2 1.5 0.3 1.4];
subplot(311);
stem(n1,x1);
axis([-1 8 0 2.1]);
n2=0:7;
x2=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7];
subplot(312);
stem(n2,x2);axis([-1 8 0 0.8]);
n=0:7;
x1=[x1 zeros(1,8-length(n1))];
x2=[zeros(1,8-length(n2)),x2];
x=x1.*x2; %注意要使用.*
subplot(313);
stem(n,x);axis([-1 8 0 0.7]);
2.序列的累加和累积:
sum(n):用于求序列的累加。
prod(n):用于求序列的累积。
clc;clear;close all;
%序列累加
N=[1 2 3 4];
sum(N)
%序列值乘积
prod(N)
ans =
10
ans =
24
3.序列的翻转:
翻转运算用fliplr函数实现,设序列x(n)用样值向量x和位置向量nx描述,翻转后的序列y(n)用样值向量y和位置向量ny描述,则实现语句为:
y=fliplr(x);
ny=-fliplr(nx);
%序列翻转
clc;clear;close all;
nx=-2:5;
x=[2 3 4 5 6 7 8 9];
ny=-fliplr(nx);
y=fliplr(x);
subplot(121);
stem(nx,x,'.');axis([-6 6 -1 9]);grid on;
xlabel('n');ylabel('x(n)');title('序列');
subplot(122);
stem(ny,y,'.');axis([-6 6 -1 9]);grid on;
xlabel('n');ylabel('x(n)');title('翻转后的序列');
4.序列移位:
设序列x(n)用样值向量x和位置向量nx描述,移位后的序列y(n)用样值向量y和位置向量ny表示,则右移n0的实现语句为:
y=x;
ny=nx+n0;
%序列移位
clc;clear;close all;
nx=-2:5;x=[9 8 7 6 5 4 3 2];
y=x;ny1=nx+4;ny2=nx-1;
subplot(211);stem(nx,x,'.');axis([-5 9 -1 9]);grid on;
xlabel('n');ylabel('x(n)');title('原序列');
subplot(223),stem(ny1,y,'.');axis([-5 9 -1 9]);grid on;
xlabel('n');ylabel('y1(n)');title('右移4位后的序列');
subplot(224);stem(ny2,y,'.');axis([-5 9 -1 9]);grid on;
xlabel('n');ylabel('y2(n)');title('左移1位后的序列');
5.连续时间信号的尺度变换:
连续时间信号的尺度变换,就是将连续信号进行扩展或压缩,即将信号的自变量t更换为at,当a>1时,信号以原点为基准,沿时间轴压缩到原来的1/a;当0<a<1时,信号以原点为基准,沿时间轴扩展到原来的1/a倍。
%矩形波的尺度变换
clc;clear;close all;
t=-4:0.01:4;
T=2;
f=rectpuls(t,T);
ft=rectpuls(4*t,T);
subplot(211);
plot(t,f);
axis([-4 4 -0.5 1.5]);
subplot(212);
plot(t,ft);
axis([-4 4 -0.5 1.5]);
6.连续时间信号的奇偶变换:
偶分量:fe(t)=1/2[f(t)+f(-t)]
奇分量:f0(t)=1/2[f(t)-f(-t)]
clc;clear;close all;
t=-4*pi:0.001:4*pi;
f=sin(t-2)+t;
f1=fliplr(f); %将信号翻转
e=1/2*(f+f1);
o=1/2*(f-f1);
subplot(311);plot(t,f);title('原信号');
subplot(312);plot(t,e);title('偶分量');
subplot(313);plot(t,o);title('奇分量');
7.连续时间信号的积分与微分:
微分:diff(function,'variable',n):function表示需要进行求导运算的信号,variable为求导运算的独立变量,n为求导的阶数,默认为一阶导数。
积分:int(function,'variable',a,b):function表示需要进行积分运算的信号,variable为积分运算的独立变量,a、b分别为积分上、下限,a、b省略时默认为不定积分。
%信号的微分
syms t f2;
f2=t*(2*heaviside(t)-heaviside(t-1))+heaviside(t-1);
t=-1:0.01:2;
subplot(121);ezplot(f2,t);
title('原函数');grid on;ylabel('x(t)');
f=diff(f2,'t',1);
subplot(122);ezplot(f,t);
title('微分函数');grid on;ylabel('x(t)');
%信号的积分
clc;clear;close all;
syms t f1;
f1=2*heaviside(t)-heaviside(t-1);
t=-1:0.01:2;
subplot(121);ezplot(f1,t);
title('原函数');grid on;
f=int(f1,'t');
subplot(122);ezplot(f,t);
grid on;title('积分函数');ylabel('x(t)');