【 MATLAB 】两个序列的卷积和运算的MATLAB实现(1)
【摘要】 设矩形脉冲 是脉冲响应 的LTI系统的输入,求输出 y(n).
下面的脚本中用到了一个自定义的函数,也就是两个信号相加的函数:
相关博文:【 MATLAB 】基本序列运算及其MATLAB的等效表示
function [y,n] = sigadd(x1,n1,x2,n2)% implements y(n) = x1(n) + x...
设矩形脉冲 是脉冲响应 的LTI系统的输入,求输出 y(n).
下面的脚本中用到了一个自定义的函数,也就是两个信号相加的函数:
相关博文:【 MATLAB 】基本序列运算及其MATLAB的等效表示
-
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; %initialization
-
y1( find( ( n >= min(n1) )&( n <= max(n1) ) == 1 ) ) = x1; %x1 with duration of y1
-
y2( find( ( n >= min(n2) )&( n <= max(n2) ) == 1 ) ) = x1; %x2 with duration of y2
-
y = y1 + y2;
直接给出MATLAB脚本:
-
clc
-
clear
-
close all
-
-
% help stepseq
-
% generate x(n) = u(n - n0); n1 <= n <= n2
-
% _____________________________________________
-
% [x,n] = stepseq(n0, n1, n2);
-
[u1,n1] = stepseq(0,-5,45);
-
[u2,n2] = stepseq(10,-5,45);
-
-
% generate signal x(n)
-
[x,n] = sigadd(u1,n1,-u2,n2);
-
-
% generate signal h(n)
-
m = -5:45;
-
h = ( (0.9).^m ).* u1;
-
-
-
% the convolution of x(h) and h(n)
-
y = conv(x,h);
-
% ensure the index
-
nyb = n(1)+ m(1);
-
nye = n(length(x)) +n(length(h));
-
ny = nyb:nye;
-
-
-
subplot(3,1,1);
-
stem(n,x);
-
title('x(n)');
-
xlabel('n')
-
-
subplot(3,1,2);
-
stem(m,h);
-
title('h(n)');
-
xlabel('n')
-
-
subplot(3,1,3);
-
stem(ny,y);
-
title('the conv of x(n) and h(n)');
-
xlabel('n')
-
xlim([-5,45]);
文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。
原文链接:reborn.blog.csdn.net/article/details/83280406
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)