You are on page 1of 69

信号与系统实验

Signals and Systems Laboratory


Lab #1. Basics for Signals and
MATLAB
Instructor:张利君
Office: 一教129
Email: zhanglj@sustech.edu.cn
Department of Electrical and
Electronic Engineering
Outline

1. Introduction
2. Basics for MATLAB
3. Signal Basics in MATLAB

信号与系统实验 Signals and Systems Laboratory 2


Part 1. Introduction

信号与系统实验 Signals and Systems Laboratory 3


Signals & Systems

信号与系统实验 Signals and Systems Laboratory 4


Contents and Grading Policy(实验内容及评价方式)
5 Lab assignments (45%) + 2 Coding tests (5%) + 2 Projects (50%)
 Lab 1. Signal Representations with MATLAB Programming(信号的表示及MATLAB
编程)(10%)
 Lab 2. Linear Time-Invariant Systems (线性时不变系统)(10%)
 Lab 3. Fourier Series Representation of Periodic Signals (周期信号的傅里叶级数
表示)(10%)
 Lab 4. The Continuous Time Fourier Transform (连续时间傅里叶变换)(10%)
 Lab 5. Prelab for Project 1(5%)
 Coding test 1&2 (5%)

• Project 1. Speech Synthesis and Perception with


Envelope Cue (语音合成与感知)
• Project 2. Motion detection via communication signals
(基于通信信号的运动检测)
Two Reports (20% for each one) of the Two Projects and
the Presentation (10%) of One Project (Project 1 or Project
2, choose it by yourselves).

信号与系统实验 Signals and Systems Laboratory 5


Regulations(课程规则)
5 Lab Assignments:
 Two students in the same class form a group
 Submit one report per lab for each group before the deadline, sign both
of your names on the report
 Submit your report through the Blackboard System

2 Projects:
 Four students in the same class form a group
 Submit one report per project for each group before the deadline
 Submit your report through the Blackboard System

 请不要迟到,做完了可以提前离开
 迟交报告一律不计分
 平常上课老师会随机提问

信号与系统实验 Signals and Systems Laboratory 6


Time Schedule(时间安排)
• Week 1 (9th September). Introduction & Lab 1 tutorial
• Week 2 (16th September). Lab 1
• Week 3 (23rd September). Lab 1 continued
• Week 4 (30th September). Lab 2 tutorial
• The week for National Day (9th October). Lab 2
• Week 5 (14th October). Lab3 tutorial
• Week 6 (21st October). Lab 3
• Week 7 (28th October). Lab 4 tutorial
• Week 8 (4th November). Lab 4
• Week 9 (11th November). Lab 5 & Project 1 tutorial
• Week 10 (18th November). SUSTech Sports Meeting on Friday, no class
• Week 11 (25th November). Project 1
• Week 12 (2nd December). Project 1 continued, coding test (30 min)
• Week 13 (9th December). Project 2 tutorial
• Week 14 (16th December). Project 2
• Week 15 (23rd December). Project 2 continued, coding test (30 min)
• Week 16 (30th December). Final Presentation

信号与系统实验 Signals and Systems Laboratory 7


Part 2. Basics for MATLAB

信号与系统实验 Signals and Systems Laboratory 8


Matrix Laboratory
 Very easy programming
language
 Powerful graphics
capabilities
 Very sleek and interactive
interface
 Great for general scientific
and engineering
computation

信号与系统实验 Signals and Systems Laboratory 9


MATLAB Desktop(软件界面)
Toolbar (工具栏)

Script Window
(脚本窗口) Workspace
(工作区)
Current Folder
(当前文件夹)

Command Window
(命令行窗口)

信号与系统实验 Signals and Systems Laboratory 10


MATLAB 的工作方式

%用plot函数画一个方波 x(t)
t=[-1 0 0 1 1 3]; 1
x=[0 0 1 1 0 0];
plot(t,x); t
xlabel('t'); 0 1

ylabel('x(t)');
axis([-1 3 0 2]);

① 直接在命令行窗口一条一条的输入命令
② 建一个名字为 example.M 的文件,然后在命令行
窗口输入文件名回车运行

信号与系统实验 Signals and Systems Laboratory 11


MATLAB 获取帮助及注释

命令行窗口输入: help + 函数名


例如 help plot
命令行窗口输入:doc 调出整个帮助界面
lookfor:关键字搜索
%: 注释符,用此符号引领一行,此符号
后的所有文字均为注释

信号与系统实验 Signals and Systems Laboratory 12


变量
 变量名由字母、数字和下划线构成,第一个字符必须是字母,变
量名不能使用关键字(关键字可以用命令 iskeyword 查看)
 大写和小写的字母视为不同的字符
 变量名长度:不超过63个字符(64位系统),对于每个系统可以
用命令 namelengthmax 查看
 不需要变量的类型说明,直接赋值,例如:num_students = 25
 特殊变量:
变量
ans pi inf NaN tic toc i, j date clock

当前正在 Not-a-number,表 秒表 秒表
圆周 无穷 虚数 当前 当前
含义 操作的默 示不定值,如0/0、 计时 计时
率 大 单位 日期 时间
认变量 ∞/∞、0*∞ 开始 结束

信号与系统实验 Signals and Systems Laboratory 13


Arrays and Matrices (数组与矩阵)
All MATLAB variables are multidimensional arrays, no matter
what type of data. A matrix is a two-dimensional array.

An array x = [1 5 3 4 2 6] or x = [1,5,3,4,2,6]

A matrix A = [1 3 5;3 6 7;0 5 8]

A= A 3-dimensional array C = zeros(3,3,2)

1 3 5 C(:,:,1) = C(:,:,2) =
3 6 7
0 5 8 0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

信号与系统实验 Signals and Systems Laboratory 14


Arrays and Matrices (数组与矩阵)
A = [2 3 5;4 6 8;2 5 1] A' inv(A)

A= ans = ans =

2 3 5 2 4 2 -4.2500 2.7500 -0.7500


4 6 8 3 6 5 1.5000 -1.0000 0.5000
2 5 1 5 8 1 1.0000 -0.5000 0

k = 10:-0.5:6
t = 0:8
k=
t=
10.0000 9.5000 9.0000 8.5000
0 1 2 3 4 5 6 7 8 8.0000 7.5000 7.0000 6.5000
6.0000

信号与系统实验 Signals and Systems Laboratory 15


Arrays and Matrices (数组与矩阵)
B = [1:3;6:-1:4;4:6] x = linspace(0,2,5)

B= B(1,1) = 1 x=
B(1,3) = 3
1 2 3 0 0.5000 1.0000 1.5000 2.0000
6 5 4
4 5 6 B(:,1) zeros 产生矩阵元素全为0的矩阵
ones 产生矩阵元素全为1的矩阵
B(3,:) ans = eye 产生单位矩阵
rand 产生(0,1)均匀分布随机数矩阵
ans = 1 randn 产生正态分布随机数矩阵
6
4 x = rand(1,3)
4 5 6
x=

0.8147 0.9058 0.1270

信号与系统实验 Signals and Systems Laboratory 16


Arrays and Matrices (数组与矩阵)
Concatenation of arrays B=
and matrices
1 3
x = [1 3];y = [5 8]; 5 8
length(X) = max(size(X))
>> A = [x y]
A= >> size(B)

1 3 5 8 ans =

>> B = [x;y] 2 2
B=
>> length(B)
1 3
5 8 ans =

信号与系统实验 Signals and Systems Laboratory 17


Data Types (数据类型)
Numeric types
(by default)

Single

信号与系统实验 Signals and Systems Laboratory 18


Data Types (数据类型)

MSB LSB
single(a) 01000110001111100111100000000000

single(b) 10110111010011001000010000000000

信号与系统实验 Signals and Systems Laboratory 19


Data Types (数据类型)

Complex number >> x = rand(1)*2

x=
>> x = 2+ 3*i
1.6294
x=
>> y = rand(1)*3
2.0000 + 3.0000i
y=

abs(x) 求复数x的模 2.7174


angle(x) 求复数x的相角(弧度) >> z = complex(x,y)
real(x) 求复数x的实部
imag(x) 求复数x的虚部 z=
conj(x) 求复数x的共轭
1.6294 + 2.7174i

信号与系统实验 Signals and Systems Laboratory 20


Data Types (数据类型)

Characters and Strings

chr = 'hello, world' >> name = 'myname';


domain = 'mydomain ';
chr = ext = 'com';
address = strcat(name, '@', domain, '.', ext)
'hello, world'
address =

'myname@mydomain.com'

信号与系统实验 Signals and Systems Laboratory 21


Operators and Elementary Operations
(运算符及基本运算)
Arithmetic Logic
+ addition A & B 逻辑与(and)
- subtraction A | B 逻辑或(or)
* multiplication ~A 逻辑非(not)
/ division
^ power Relational
‘ complex conjugate transpose
A < B 小于
A > B 大于
A <= B 小于等于
A >= B 大于等于
A == B 等于
A ~= B 不等于

信号与系统实验 Signals and Systems Laboratory 22


Operators and Elementary Operations
(运算符及基本运算)
>> A = [1 2 3;4 5 6;7 8 9] >> B = [3 5 2;5 3 8;3 6 9] How about
A^2
A= B= X/Y
X\Y
1 2 3 3 5 2 2*A
4 5 6 5 3 8 A + 3j*B
7 8 9 3 6 9 (A + 3j*B)’

>> X = A + B Y=A- B >> Z = A * B >> T = A'

X= Y= Z= T=

4 7 5 -2 -3 1 22 29 45 1 4 7
9 8 14 -1 2 -2 55 71 102 2 5 8
10 14 18 4 2 0 88 113 159 3 6 9

信号与系统实验 Signals and Systems Laboratory 23


Operators and Elementary Operations
(运算符及基本运算)
>> A = [1 2 3;4 5 6;7 8 9] >> B = [3 5 2;5 3 8;3 6 9] How about
A.^2
A= B= (A + 3j*B).’

1 2 3 3 5 2
4 5 6 5 3 8
7 8 9 3 6 9

>> Z = A * B >> A.*B >> A./B

Z= ans = ans =

22 29 45 3 10 6 0.3333 0.4000 1.5000


55 71 102 20 15 48 0.8000 1.6667 0.7500
88 113 159 21 48 81 2.3333 1.3333 1.0000

信号与系统实验 Signals and Systems Laboratory 24


Useful Commands
(几个常用命令)

>> who
>> whos
>> clear
>> clc
>> dir
>> pause

信号与系统实验 Signals and Systems Laboratory 25


Functions (函数文件)

 M文件的第一行包含function
 功能: 建立一个函数,可以同MATLAB的库
函数一样使用
x(t)
1
例:编一个绘制图示波形的函数

t
1、先编写一个与函数同名的M文件 -1 0 1

function y = tri(t) 2、调用函数tri,并画出它的波形


y=[abs(t)<=1].*(1-abs(t));
t=-2:0.05:2;
plot(t,tri(t));

信号与系统实验 Signals and Systems Laboratory 26


Functions (函数文件)

function myOutput = myFunction(x)

function [one,two,three] = myFunction(x)

function myFunction(x)

function [one,two,three] = myFunction(x,y,z)

信号与系统实验 Signals and Systems Laboratory 27


Flow Control (流程控制)
Similar to almost all programming language, MATLAB program has
three basic structures:
–Sequence, Selection and Repetition

Statement 1 Condition ?
Condition ?
YES NO YES
Statement 2
Statement 1 Statement 1
Statement 2
Statement 3

Sequence Repetition: for


Selection: if
& while

信号与系统实验 Signals and Systems Laboratory 28


Flow Control (流程控制)
Selection: if if ((a>3) & (b==5))
statements;
if expression end
statements
elseif expression if (a<3)
statements;
statements elseif (b~=5)
else statements;
statements end
end
if (a<3)
statements1;
else
statements2;
end

信号与系统实验 Signals and Systems Laboratory 29


Exercise 1.1 Selector.m

Write a script to add ‘5’ to a number if it


is greater than ‘10’, else add ‘10’.

信号与系统实验 Signals and Systems Laboratory 30


Flow Control (流程控制)
Repetition: for
for i=1:100
for index = values statements
end
statements
end for j=1:3:200
statements
end
例: 编写计算s=1+2+3+…+100的MATLAB程序
for m=13:-0.2:-21
s = 0; statements
for n=1:100 end
s=s+n;
end for k=[0.1 0.3 -13 12 7 -9.3]
statements
end

信号与系统实验 Signals and Systems Laboratory 31


Flow Control (流程控制)
Repetition: while
while ((a>3) & (b==5))
while expression statements
statements end
end

s = 0;
n = 1;
eps = 1e-6;
while 1/(n*n) > eps
s = s+1/(n*n);
n = n+1;
end
fprintf ('s=%.5f\n',s)

信号与系统实验 Signals and Systems Laboratory 32


Exercise 1.2 Accumulator.m

Write a script to output the sum of


numbers from 1 to the number input.

信号与系统实验 Signals and Systems Laboratory 33


Test 1

IF (The input number N is an even integer)


Sum=2+4+6+…+N;
IF (The input number N is an odd integer)
Sum=1+3+5+…+N;

信号与系统实验 Signals and Systems Laboratory 34


Basic Graphics Commands
(基本图形命令)
plot函数

t = linspace(0,4*pi,512);
plot(t,sin(t),t,cos(t),'-.');
title('my figure');
xlabel('t');
legend('sin(t)','cos(t)');

信号与系统实验 Signals and Systems Laboratory 35


Basic Graphics Commands
(基本图形命令)
plot函数
t = linspace(0,4*pi,100);
y = sin(t).*exp(-t/3);
plot(t,y,'b-');
title('y = sin(t).*exp(-t/3)');
xlabel('t');
axis([0 4*pi -0.8 0.8]);

信号与系统实验 Signals and Systems Laboratory 36


Basic Graphics Commands
(基本图形命令)
stem函数

k = 0:39;
stem(k,cos(0.9*pi*k));
title('cos(0.9\pik)');

信号与系统实验 Signals and Systems Laboratory 37


Basic Graphics Commands
(基本图形命令)
x = linspace(0,4*pi,100); Multiple plots in a figure
y = sin(x);
figure(1);
plot(x, y,'r--','linewidth',2);
hold on;
plot(x, y+1,'k--','linewidth',2);
legend('wave_1', 'wave_2');

信号与系统实验 Signals and Systems Laboratory 38


Basic Graphics Commands
(基本图形命令)
x = linspace(0,4*pi,100); subplots
y = sin(x);
subplot(2,1,1);
plot(x, y);
subplot(2,1,2);
plot(x, abs(y));

信号与系统实验 Signals and Systems Laboratory 39


Part 3. Signal Basics in MATLAB

信号与系统实验 Signals and Systems Laboratory 40


Exponentials
f (t )
t Ke t (  0)
f (t )  Ke
K
f (t )  (2 - e-2t )u(t ) Ke t (  0)
Ke t (  0)
t = -1:0.01:10;
t1 = -1:0.01:-0.01; 0 t
t2 = 0:0.01:10;
u =[zeros(1,length(t1)),ones(1,length(t2))];
f = (2-exp(-2*t)).*u;
plot(t,f)
axis([-1,10,0,2.1]) Help heaviside
syms t;
f = sym((2-exp(-2*t))*heaviside(t));
fplot(f,[-1,10]);
axis([-1,10,0,2.1]) Help syms sym
fplot
信号与系统实验 Signals and Systems Laboratory 41
Sinusoids
f (t )  K sin(t +  ) f t 
T
K
t
f (t )  cos( ) u (t ) - u (t - 4) 2π
2 
O 2π t



t = -2:0.01:8;
f = 0.*(t<0) + cos(pi*t/2).*(t>0 & t<4) + 0.*(t>4);
plot(t,f)

syms t;
f=sym(cos(pi*t/2)*[heaviside
(t)-heaviside(t-4)]);
fplot(f,[-2,8]);

信号与系统实验 Signals and Systems Laboratory 42


Complex Exponentials
f (t )  Kest  Ke( + j )t  Ke t cos t + jKe t sin t
f (t )  e(0.4+ j 8)t
syms t; omega = 0.4 + j*8;
f = sym(exp(omega*t));
f1 = real(f);f2 = imag(f);f3 = abs(f);f4 = angle(f);
subplot(2,2,1);
fplot(f1,[0,10]);
title('real part of exp(0.4+j8)t');
grid on;
subplot(2,2,2);
fplot(f2,[0,10]);
title('imaginary part of exp(0.4+j8)t');
grid on;
subplot(2,2,3);
fplot(f3,[0,10]);
title('magnitude of exp(0.4+j8)t');
grid on;
subplot(2,2,4);
fplot(f4,[0,2]);
title('phase of exp(0.4+j8)t');

信号与系统实验 Signals and Systems Laboratory 43


Exercise 1.3 ComExp

Plot the real part, imaginary part, magnitude


and phase of the continuous-time signal
𝝅 𝝅
𝒇 𝒕 = 𝟐 + 𝒆𝒙𝒑 𝒋 𝒕 + 𝒆𝒙𝒑 𝒋 𝒕 .
𝟒 𝟐

信号与系统实验 Signals and Systems Laboratory 44


信号与系统实验 Signals and Systems Laboratory 45
Sinc Function (抽样函数)

sin 𝜋𝑡
𝑠𝑖𝑛𝑐 𝑡 = 𝑡≠0
𝜋𝑡
1 𝑡=0

① even function, sinc(t) = sinc(-t)


② sinc(0) = 1, lim sinc 𝑡 = 1
𝑡→0
③ sinc(n) = 0, for integers n = ±1, ±2, ⋯
∞ ∞
④ 0 sinc t dt = 1/2, −∞ sinc t dt = 1
⑤ lim sinc t = 0
t→±∞
1 π jωt
⑥ sinc t = e dω
2π −π

信号与系统实验 Signals and Systems Laboratory 46


Rectangular Pulse & Square Wave
% Generate 4 seconds of a rectangular pulse with a
% sample rate of 1KHz and a width of 1s,
% centered about t = 2s.
fs = 1000; % Number of samples per second
t = 0:1/fs:4; % Time vector
x = rectpuls(t-2,1); % Generating rectangular pulse
plot(t,x); % Plotting the pulse
axis([0 4 -0.5 1.5]);

Help rectpuls
% Generate a 10 Hz square wave
with duty cycle 50%.
t = 0:.0001:0.5;
y = square(2*pi*10*t,50);
plot(t,y);
axis([0,0.5,-1.2,1.2]);

Help square

信号与系统实验 Signals and Systems Laboratory 47


Triangular Pulse
% Create a triangular pulse with width 0.4.
fs = 10000; % Sampling frequency
t = -2:1/fs:2; % Time Vector
w = 1; % Triangle Width
x = tripuls(t,w); % Sampled aperiodic triangle
plot(t,x,'b-');
hold on;
s1 = 0.5; % Skew parameter s = 0.5
y = tripuls(t,w,s1);
plot(t,y,'r:');
hold on;
s2 = 1; % Skew parameter s = 1
z = tripuls(t,w,s2);
plot(t,z,'g--');
xlabel('Time (sec)');ylabel('Amplitude');

Help tripuls

信号与系统实验 Signals and Systems Laboratory 48


Discrete-time Signals
x[n]  n  u[n] - u[n - 8]

t = 0:7;
t1 = -10:15;
f = [zeros(1,10),t,zeros(1,8)];
stem(t1,f);
axis([-10,15,0,10]);
grid on;

𝑥 𝑛 = (−1/2)𝑛 𝑢[𝑛]

n = -3:6;
y = (n>=0);
x = (-0.5).^n.*y;
stem(n,x,'filled')

信号与系统实验 Signals and Systems Laboratory 49


Exercise 1.4 ComExpSeries

Plot the real part and imaginary part of the complex


exponential series

𝝅
𝒙𝟏 [𝒏] = 𝒆𝒙𝒑 𝒋 𝒏 , 𝒙𝟐 [𝒏] = 𝒆𝒙𝒑 𝒋𝟑𝒏
𝟔

Are they periodic?

信号与系统实验 Signals and Systems Laboratory 50


信号与系统实验 Signals and Systems Laboratory 51
Comparison between 𝑒 𝒋𝝎𝟎 𝑡 and 𝑒 𝒋𝝎𝟎 𝑛

𝒙 𝒕 = 𝑒 𝒋𝝎𝟎 𝑡 𝒙 𝒏 = 𝑒 𝒋𝝎𝟎 𝒏
𝑒 𝒋𝝎𝟎𝑡 ≠ 𝑒 𝒋𝝎𝟏 𝑡 (distinct signals) if 𝑒 𝑗𝜔0 𝑛 = 𝑒 𝑗𝜔1𝑛 (identical signals) if
𝜔0 ≠ 𝜔1 𝜔1 = 𝜔0 + 2𝑘𝜋
2𝑘𝜋
𝑥 𝑡+ = 𝑥(𝑡) periodic for any 𝑥 𝑛 + 𝑘𝑁 = 𝑥[𝑛] periodic only if
𝜔0
𝜔0 = 2𝜋𝑚/𝑁 for some integers N
choice of 𝜔0 and m
Fundamental frequency 𝜔0 Fundamental frequency 𝜔0 /𝑚
Fundamental period: Fundamental period:
𝜔0 = 0: undefined 𝜔0 = 0: undefined
𝜔0 ≠ 0: 2𝜋/𝜔0 𝜔0 ≠ 0: 2𝜋𝑚/𝜔0

信号与系统实验 Signals and Systems Laboratory 52


Harmonically Related Complex Exponentials
𝝓𝒌 (𝒕) = 𝑒 𝒋𝒌𝝎𝟎 𝑡 𝜔0 = 𝜋/4

信号与系统实验 Signals and Systems Laboratory 53


Harmonically Related Complex Exponentials
𝝓𝒌 [𝒏] = 𝑒 𝒋𝒌(𝟐𝝅/𝑵)𝒏 𝑁=8

信号与系统实验 Signals and Systems Laboratory 54


Singularity Functions
Unit step function (continuous time)
1 t 0
u (t )   Undefined at t= 0!
0 t0
% Use array representation directly
t1 = -5:0.01:2;
t2 = 2:0.01:5;
% Use sign funciton
1 t = [t1,t2];
t = -5:0.01:5;
x =[zeros(1,length(t1)),ones(1,length(t2))];
plot(t,x); 2 x = 0.5 + 0.5*sign(t-2);
axis([-5,5,-0.1,1.1]); plot(t,x);
axis([-5,5,-0.1,1.1]);

% Call stepfun
T = -5:0.01:5; % Use symbolic math function
T0 = 2; syms t;
3 x = stepfun(T,T0); 4 x = heaviside(t-2);
plot(T,x); fplot(x);
axis([-5,5,-0.1,1.1]); axis([-5,5,-0.1,1.1]);

信号与系统实验 Signals and Systems Laboratory 55


Singularity Functions
% Funciton to calculate unit step for each input t
function y = unit_step(t)
y = (t>=0);

% Main function, call function 'y = unit_step(t)'


5 t = -5:0.01:5;
for i = 1:length(t)
ti = t(1,i);
y(1,i) = unit_step(ti-2);
end
plot(t,y);
axis([-5,5,-0.1,1.1]);

% Funciton to calculate unit step for each input t


function y = unit_step(t)
y = (t>=0);

6 % Use function handle to call functions defined by users


t = -5:0.01:5;
x = @unit_step;
plot(t,x(t-2));
axis([-5,5,-0.1,1.1]);
Help function_handle

信号与系统实验 Signals and Systems Laboratory 56


Singularity Functions
Unit impulse function (continuous time)
 (t )  0 (t  0) 1
 𝛿∆ 𝑡 − 𝑡1 = ∆ 𝑡1 < 𝑡 < 𝑡1 + ∆ 𝛿 𝑡 − 𝑡1 = lim 𝛿∆ (𝑡 − 𝑡1 )
 ∆→0
   (t )dt  1 0 𝑜𝑡ℎ𝑒𝑟
 -

% Use array representation directly


t1 = -5:0.01:1.99;
t2 = 2.01:0.01:5;
1 t = [t1,2,t2];
x=[zeros(1,length(t1)),inf,zeros(1,length(t2))];
plot(t,x);

% Call dirac function


t = -5:0.01:5; % Call symbolic function dirac
2 x = dirac(t-2); syms t;
plot(t,x); 3 x = dirac(t-2);
fplot(x);
int(x,t,-inf,inf) % ans = 1

信号与系统实验 Signals and Systems Laboratory 57


Singularity Functions
Unit step sequence (discrete time)
1, n0
u[n]  
0, n0

n = -10:10;
y=[zeros(1,10),ones(1,11)];
stem(n,y);

% u[n-2]
n = -10:10;
n0 = 2;
u = ((n-n0)>=0);
stem(n,u);

信号与系统实验 Signals and Systems Laboratory 58


Singularity Functions
Unit impulse sequence (discrete time)

1 𝑛=0
𝛿𝑛 =
0 𝑛≠0

% Use array representation directly


n = -10:10;
y=[zeros(1,10),1,zeros(1,10)];
stem(n,y);

% Call gauspuls
n = -10:10;
y = gauspuls(n-2);
stem(n,y);

n = -10:10;
n0 = 2;
y = ((n-n0)==0);
stem(n,y);

信号与系统实验 Signals and Systems Laboratory 59


Singularity Functions
 (t ) u(t)

1
(1)

t 0 t
0
f (t ) (t )  f (0) (t )
t
(1) (6)  -
 ( )d  u (t )
d
 
u (t )   (t )
(2) -
 (t ) f (t )dt  f (0)   (t )dt  f (0)
-
(7)
dt
0 t0
(3) f (t ) (t - t0 )  f (t0 ) (t - t0 ) (8) f (t )u (t )  

 f (t ) t  0
(4) -
 (t - t0 ) f (t )dt  f (t0 )
(9) 
t
 ( - t0 )d  u (t - t0 )
-
(5)  (t )   (-t ) d
(10) u (t - t0 )   (t - t0 )
dt

信号与系统实验 Signals and Systems Laboratory 60


Singularity Functions

(1) x[n] [n]  x[0] [n] (5)   [k ]  u[n]


k -
+
(6) u[n] - u[n - 1]   [n]
(2)   [k ]x[k ]  x[0] n0
k - 0
(7) x[n]u[n]  
(3) x[n] [n - n0 ]  x[n0 ] [n - n0 ]  x[n] n  0
n
+
(8)   [k - n0 ]  u[n - n0 ]
(4)   [k - n ]x[k ]  x[n ]
k -
0 0 k -

(9) u[n - n0 ] - u[n - n0 - 1]   [n - n0 ]

信号与系统实验 Signals and Systems Laboratory 61


Addition and Multiplication of Signals
sin 𝜔𝑡 sin 𝜔𝑡

sin 8𝜔𝑡 sin 8𝜔𝑡

sin 𝜔𝑡 + sin 8𝜔𝑡 sin 𝜔𝑡 ∗ sin 8𝜔𝑡

信号与系统实验 Signals and Systems Laboratory 62


Transformations of Time Index
syms t;
f = sym(heaviside(t)-heaviside(t-2)+(1+t)*(heaviside(t+1)-heaviside(t)));
subplot(2,2,1);fplot(f,[-2,3]);
axis([-2 3 -0.2 1.2]);
title('f(t)');grid on;
f1 = subs(f,t,t+5);
subplot(2,2,2);fplot(f1,[-7,-2]);
axis([-7 -2 -0.2 1.2]);
title('f(t+5)');grid on;
f2 = subs(f,t,-t+5);
subplot(2,2,3);fplot(f2,[2,7]);
axis([2 7 -0.2 1.2]);
title('f(-t+5)');grid on;
f3 = subs(f,t,-2*t+5);
subplot(2,2,4);fplot(f3,[-1,4]);
axis([-1 4 -0.2 1.2]);
title('f(-2t+5)');grid on;

Help subs

信号与系统实验 Signals and Systems Laboratory 63


Transformations of Time Index
1 𝑛 = −2
2 𝑛 = −1
3 𝑛=0
𝑥 𝑛 = 3 𝑛=1
3 𝑛=2
3 𝑛=3
0 𝑜𝑡ℎ𝑒𝑟

n = -6:6;
x1 = (n+3).*((n>=-2)-(n>=1))
+3.*((n>=1)-(n>=4));
subplot(2,2,1);stem(n,x1,'.');
title('x[n]');
x2 = fliplr(x1);
subplot(2,2,2);stem(n,x2,'.');
title('x[-n]');
n3 = n + 2;x3 = x1;
subplot(2,2,3);stem(n3,x3,'.');
title('x[n-2]');
n4 = n -2;x4 = x1; Help fliplr, flipud
subplot(2,2,4);stem(n4,x4,'.');
title('x[n+2]');

信号与系统实验 Signals and Systems Laboratory 64


Signal Decomposition
1
even part of signal 𝒇 𝒕 𝑓𝑒 𝑡 = 𝑓 𝑡 + 𝑓 −𝑡
2

1
odd part of signal 𝒇(𝒕) 𝑓𝑜 𝑡 = 𝑓 𝑡 − 𝑓 −𝑡
2

f e (t )  f e (-t ) f o (t )  - f o ( -t )

𝑓 𝑡 = 𝑓𝑒 𝑡 + 𝑓𝑜 𝑡 𝑓 −𝑡 = 𝑓𝑒 𝑡 − 𝑓𝑜 𝑡

信号与系统实验 Signals and Systems Laboratory 65


Exercise 1.5 SigTrans
𝒙𝟏 𝒕 = 𝟒 − 𝒕 𝒖 𝒕 − 𝒖(𝒕 − 𝟒) , 𝒙𝟐 𝒕 = sin 2𝜋𝑡
Plot the following signals in one figure by using subplot.
① 𝒙𝟑 𝐭 = 𝒙𝟏 𝐭 + 𝒙𝟐 𝐭
② 𝒙𝟒 𝐭 = 𝒙𝟏 𝐭 ∗ 𝒙𝟐 𝐭
③ 𝒙𝟓 𝐭 = even part of 𝒙𝟏 (𝐭)
④ 𝒙𝟔 𝐭 = odd part of 𝒙𝟏 (𝐭)
⑤ 𝒙𝟕 𝐭 = 𝒙𝟐 𝐭 ∗ 𝒙𝟑 𝐭 − 𝟏

信号与系统实验 Signals and Systems Laboratory 66


信号与系统实验 Signals and Systems Laboratory 67
Differentiation and Integration

fs = 10000; t = -2:1/fs:2; w = 1;
x = tripuls(t,w);
plot(t,x,'b-'); hold on;
x1 =diff(x)*fs;
plot(t(1:length(t)-1),x1,'r-.');hold on;
syms s;
x =sym((2*s+1).*(heaviside(s+0.5)-heaviside(s))+(1-
2*s).*(heaviside(s)-heaviside(s-0.5)));
y = int(x);fplot(y,'m');
axis([-1,1,-2.5,2.5]);
Help int

信号与系统实验 Signals and Systems Laboratory 68


Lab#1 Assignment
1.4 & 1.5

Deadline: 10:00am September 30th


Submit the report in word or pdf
format through Blackboard.

信号与系统实验 Signals and Systems Laboratory 69

You might also like