【 MATLAB 】信号处理工具箱的信号产生函数之 square 函数简记
因为案例需要,所以这里先看一下linspace这个函数的用法:
y = linspace(x1,x2);
均匀产生位于x1 到 x2 之间的100个点;
y = linspace(x1,x2,n);
均匀产生位于x1 到 x2 之间的n个点。
generates a square wave with period 2π for the elements of the time array
x
= square(t
)t
.square
is similar to the sine function but creates a square wave with values of –1 and 1.产生一个周期为 2π 的方波信号;
generates a square wave with specified duty cycle
x
= square(t
,duty
)duty
. The duty cycle is the percent of the signal period in which the square wave is positive.产生一个周期为 2π 的方波信号,duty表示占空比,例如duty = 30,则占空比为30%,也就是正幅度与整个周期的比值。
案例1:在0 到 3π之间等间隔产生100个点,然后产生一个周期为2π的方波
-
%Create a vector of 100 equally spaced numbers from 0 to 3π. Generate a square wave with a period of 2π.
-
clear
-
clc
-
close all
-
t = linspace(0, 3*pi);
-
x = square(t);
-
-
-
plot(t/pi,x,'.-',t/pi,sin(t)); %Plot the square wave and overlay a sine. Normalize the x-axis by .
-
xlabel('t / \pi')
-
grid on
在 -pi 到 2*pi 之间等间隔产生121个点作为时间轴,产生一个幅值为1.15的周期方波,同时在同一幅图上画一个正弦波,参数与方波一致;
-
%evaluate square(2*t) at 121 equally spaced numbers between -pi and 2*pi .
-
%Change the amplitude to 1.15 . Plot the wave and overlay a sine with the same parameters.
-
clear
-
clc
-
close all
-
t = linspace(-pi,2*pi,121);
-
x = 1.15*square(2*t);
-
-
plot(t/pi,x,'.-',t/pi,1.15*sin(2*t))
-
xlabel('t / \pi')
-
grid on
文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。
原文链接:reborn.blog.csdn.net/article/details/82854135
- 点赞
- 收藏
- 关注作者
评论(0)