这是一个样本对样本的相加。表示式为:
注意:序列的位置要对应,长度要相等,如果长度不等,则要扩大或延长使长度相等且位置对应。
对应的函数为:
function [y,n] = sigadd(x1,n1,x2,n2)% implements y(n) = x1(n) + x2(n)% [y,n] = sigadd(x1,n1,x2,n2)%——————————————————————————————% y = sum sequence over n, which includes n1 and n2% x1 = first sequence over n1% x2 = second sequence over n2( n2 can be different from n1)%n = min( min(n1), min(n2) ):max( max(n1), max(n2) ); %duration of y(n)y1 = zeros(1,length(n)); y2 = y1; %initializationy1( find( ( n >= min(n1) )&( n <= max(n1) ) == 1 ) ) = x1; %x1 with duration of y1y2( find( ( n >= min(n2) )&( n <= max(n2) ) == 1 ) ) = x1; %x2 with duration of y2y = y1 + y2;1.2.3.4.5.6.7.8.9.10.11.12.13.
代码中用到了find线性索引函数,不了解的话可以参考博文:【 MATLAB 】find 函数的使用(线性索引)
这是一个样本对样本的相乘(或称为点乘‘.*’),表示式为:
对+运算符所有的限制同样对.*运算符适用。
下面直接给出函数:
function [y,n] = sigmult(x1,n1,x2,n2)% implements y(n) = x1(n)* x2(n)%[y,n]=sigmult(x1,n1,x2,n2)%_____________________________% y = product sequence over n, which includes n1 and n2% x1 = first sequence over n1% x2 = second sequence over n2( n2 can be different from n1)%n = min( min(n1), min(n2) ):max( max(n1), max(n2) ); %duration of y(n)y1 = zeros(1,length(n)); y2 = y1; %initializationy1( find( ( n >= min(n1) )&( n <= max(n1) ) == 1 ) ) = x1; %x1 with duration of y1y2( find( ( n >= min(n2) )&( n <= max(n2) ) == 1 ) ) = x2; %x2 with duration of y2y = y1 .* y2;1.2.3.4.5.6.7.8.9.10.11.12.13.
在MATLAB中,这个运算对样本值用函数fliplr(x)实现,对样本位置通过函数-fliplr(n)实现,函数如下:
function [y,n] = sigfold(x,n)%implements y(n) = x(-n)%___________________________% [y,n] = sigfold(x,n)y = fliplr(x);n = -fliplr(n);1.2.3.4.5.6.
不了解fliplr(x)的话,看博文:【 MATLAB 】fliplr 函数介绍(从左到右翻转阵列)
a{ x(n) } = { a* x(n) }
在MATLAB中,直接使用*运算符就可以了。
关于移位,我单独写了一篇博文:
【 MATLAB 】序列运算之序列移位的函数实现
样本累加区别于信号相加,它是将该序列的样本值全部加起来,使用 sum( x(n1:n2) )函数来实现。
样本乘积有别于信号相乘,它是将该序列的样本值连乘得到,使用函数 prod( x(n1:n2) )即可实现。
prod函数的相关知识,见博文:【 MATLAB 】prod 函数介绍(Product of array elements)
一个序列的能量有下式给出:
下面给出两种方法计算信号能量:
Ex = sum( x.* conj(x) ) % one approachEx = sum( abs(x) .^2 ) % another approach1.2.
基波周期为N的周期序列 的平均功率给出为:
相应的MATLAB代码为:
P=(1/N)sum( abs( x(1:N-1) ).^2 )1.
令
,
确定并画出下列序列:
a.
b.
题解:
clcclearclose all%generate x(n)n = [-2:10];x = [1:7,6:-1:1];subplot(3,1,1)stem(n,x);title('original sequence');xlabel('n');ylabel('x(n)');%x1(n)=2x(n-5)-3x(n+4)[x11,n11]= sigshift(x,n,5);[x12,n12]= sigshift(x,n,-4);[x1,n1] = sigadd(2*x11, n11, -3*x12, n12);subplot(3,1,2)stem(n1,x1);title('sequence in example a');xlabel('n');ylabel('x1(n)');%x2(n) = x(3-n) + x(n)x(n-2)[x21,n21]=sigfold(x,n);[x21,n21] = sigshift(x21,n21,3);[x22,n22] = sigshift(x,n,2);[x22,n22] = sigmult(x22,n22,x,n);[x2,n2] = sigadd(x21,n21,x22,n22);subplot(3,1,3);stem(n2,x2);title('sequence in example b');xlabel('n');ylabel('x2(n)');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.30.31.32.33.34.35.36.
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删