当前位置:网站首页>MATLAB实例:阶跃函数的两种表达方式
MATLAB实例:阶跃函数的两种表达方式
2022-07-06 09:25:00 【Bitter tea seeds】
文章目录
前言
阶跃函数在MATLAB中有两种调用函数:
heaviside()函数、stepfun()函数
下面我们就来看看它俩的区别和用法。
一、heaviside()函数
1.heaviside()函数的介绍
如下图MATLAB字典上的介绍,可以看见heaviside函数的调用很简单:H = heaviside(x);并且heaviside是一个不连续的函数。它返回 0 表示 x < 0,返回 1/2 表示 x = 0,返回 1 表示 x > 0。
简单画heaviside
syms x
fplot(heaviside(x), [-2, 2])
2.heaviside()实例
代码如下所示
>> T=0.01;%步长
>> t1=0;t2=3;t3=-2;t4=2;%坐标参数
>> t5=t1:T:t2;%t5取值范围;
>> t6=t3:T:t4;%t6取值范围;
>> f1=2*exp(-2*t5);%指数函数
>> f2=3*(heaviside(t6-1)-heaviside(t6-2));%门函数
>> [y]=conv(f1,f2);%将卷积设为矩阵
>> y=y*T;t=(t1+t3):T:(t2+t4);%卷积的取值范围
>> subplot(3,1,1);plot(t5,f1,'r');axis([(t1+t3),(t2+t4),min(f1),max(f1)+0.5]);%设置坐标轴
>> ylabel('f1(t)指数曲线');line([0,0],[0,2.5]);title('信号卷积');
>> subplot(3,1,2);plot(t6,f2);axis([(t1+t3),(t2+t4),min(f2),max(f2)+0.5]);
>> ylabel('f2(t)门函数');
>> subplot(3,1,3);plot(t,y,'m');axis([(t1+t3),(t2+t4),min(y),max(y)+0.5]);ylabel('y(t)卷积合成曲线');
二、stepfun()函数
1.stepfun()函数的介绍
stepfun函数的调用stepfun(x,y)其中x代表横坐标和y代表纵坐标. 其中x必须是一个升序的向量, y的长度比x大1。
简单举例
代码如下(示例):
>> b=-5:0.01:20;%定义时间样本
>> b0=0;%信号发生突变的时刻
>> ut=stepfun(b,b0);%产生单位的阶跃信号
>> plot(b,ut),axis([-5,20,-2.5,10])%坐标轴
2.stepfun()实例
代码如下(示例):
>> T=0.01;%步长
>> t1=0;t2=3;t3=-2;t4=2;%坐标参数
>> t5=t1:T:t2;%t5取值范围;
>> t6=t3:T:t4;%t6取值范围;
>> f1=2*exp(-2*t5);%指数函数
>> f2=3*(stepfun(t6,-1)-stepfun(t6,2));%门函数
>> [y]=conv(f1,f2);%将卷积设为矩阵
>> y=y*T;t=(t1+t3):T:(t2+t4);%卷积的取值范围
>> subplot(3,1,1);plot(t5,f1,'r');axis([(t1+t3),(t2+t4),min(f1),max(f1)+0.5]);%设置坐标轴
>> ylabel('f1(t)指数曲线');line([0,0],[0,2.5]);title('信号卷积');
>> subplot(3,1,2);plot(t6,f2);axis([(t1+t3),(t2+t4),min(f2),max(f2)+0.5]);
>> ylabel('f2(t)门函数');
>> subplot(3,1,3);plot(t,y,'m');axis([(t1+t3),(t2+t4),min(y),max(y)+0.5]);ylabel('y(t)卷积合成曲线');
总结
以上就是今天要讲的内容,本文仅仅简单介绍了heaviside()函数、stepfun()函数的使用,而MATLAB提供了大量能使我们快速便捷地处理数据的函数和方法,都等待着我们的探索和使用。
小刘的悲催日常,终于要转运了
小刘一大早就到老板的办公室,委婉的说:“老板你看我这两天挺辛苦的,一直在加班,你看这个加班费……”
“什么加班费?我不知道你说的什么?公司里培养着你,你要什么加班费?”
老板一脸不屑的瞅着小刘。
小刘涨红了脸,半天说不出一个字来;老板看着小刘,吼道:“还不快去工作,延误了项目提交,我扣你工资!”
小刘走回了工位上,这时候手机突然蹦传来一条消息:十万月薪,心动联系……
边栏推荐
- In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
- The latest query tracks the express logistics and analyzes the method of delivery timeliness
- How to rename multiple folders and add unified new content to folder names
- Lab 8 file system
- ucore lab 2
- LeetCode#198. raid homes and plunder houses
- How to solve the poor sound quality of Vos?
- Video scrolling subtitle addition, easy to make with this technique
- LeetCode#2062. Count vowel substrings in strings
- Crawler series (9): item+pipeline data storage
猜你喜欢
What is "test paper test" in software testing requirements analysis
線程及線程池
ucore lab 2
安全测试入门介绍
Sleep quality today 81 points
STM32學習記錄:輸入捕獲應用
Sorting odd and even subscripts respectively for leetcode simple problem
MySQL数据库(四)事务和函数
What are the software testing methods? Show you something different
软件测试工作太忙没时间学习怎么办?
随机推荐
Pedestrian re identification (Reid) - data set description market-1501
Leetcode notes - dynamic planning -day6
CSAPP家庭作業答案7 8 9章
MySQL数据库(二)DML数据操作语句和基本的DQL语句
Currently, mysql5.6 is used. Which version would you like to upgrade to?
Which version of MySQL does php7 work best with?
Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
学习记录:TIM—电容按键检测
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
Do you know the advantages and disadvantages of several open source automated testing frameworks?
ucorelab3
[200 opencv routines] 98 Statistical sorting filter
The maximum number of words in the sentence of leetcode simple question
Mysql database (I)
线程及线程池
JS --- detailed explanation of JS DOM (IV)
Programmers, how to avoid invalid meetings?
Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years
Maximum nesting depth of parentheses in leetcode simple questions
Future trend and planning of software testing industry