如何在MATLAB中产生方波

966 views (last 30 days)
md
md 2014年6月16日
你好,
我打算通过以下特征来产生与时间的方波:
I want to generate square-wave force demand of 1 KN at 10 Hz. That means amplitude will be between 0 to 1000 and time will be between 0 to 1 (sec) with .1 interval.
Please someone help me.

接受的答案

Image Analyst
Image Analyst 2014年6月16日
Edited:Image Analyst on 24 Nov 2020
进行一个时期,然后使用repmat()根据需要复制多次。
现在,%将一个周期振幅为1000和200个元素。
Oneperiod = 1000 * [一个(1,100),零(1,100)];
% 200 elements is supposed to be 0.1 seconds so find out delta t.
dt = 0.1 / numel(onePeriod);
%定义周期数。
numcycles = 10;
% Copy this period that many times.
FullWaveForm = repmat(Oneperiod,[1,Numcycles]);
%使时间轴从0到1秒。
t = dt *(0 :( numel(fullwaveform)-1));
%现在绘制它。
情节(t,fullwaveform,'b-',,,,'行宽',2);
fontsize = 20;
xlabel('Time (seconds)',,,,'字体大小', 字体大小);
ylabel('Amplitude',,,,'字体大小', 字体大小);
标题(“有10个周期的方波”,,,,'字体大小', 字体大小);
gridon;
2条评论
Image Analyst
Image Analyst 2017年6月15日
我不知道这意味着什么。什么是“饱和块”?那是simuli金宝appnk吗?海报说“在MATLAB中”,但如果您的功能适用于Simulink,那么您的帖子也许会帮助Simulink用户。金宝app

登录发表评论。

More Answers (4)

Rashmil Dahanayake
Rashmil Dahanayake 2014年6月16日
t = 0:.001:1;
f=10;
sq=1000*0.5*(square(2*pi*f*t)+1);
plot(t,sq)

比尔·塔布斯(Bill Tubbs)
根据Rashmil Dahanayake的想法,我做出了一个简单的功能,可以在离散时间内产生常规的方波。
functionsq = square_dt(n,ofend)
百分比在离散时间内
重复= n/ofere;
sq = square(2*pi*linspace(0,repeats-1/n,n));
结尾
(Works best when 时期 是一个偶数)
例子
>> square_dt(10,4)
ans =
1 1 -1 -1 1 1 -1 -1 1 1 1
如果您只需要正循环,请像Rashmil的那样修改代码:
functionsq = square_dtp(n,period)
百分比在离散时间内
重复= n/ofere;
sq =(square(2*pi*linspace(0,repots-1/n,n))+1)/2;
结尾
例子
>> square_dtp(10,4)
ans =
1 1 0 0 1 1 0 0 1 1 1

udhaya ram  mohan
Udhaya Ram Mohan 2016年10月18日
我需要只用积极循环产生方波,请给我发送一个代码
1条评论
沃尔特·罗伯森(Walter Roberson)
Rashmil Dahanayake's Answer already only generates positive values.

登录发表评论。


pisini padmaja
pisini padmaja 2020年11月23日
Edited:Image Analyst on 24 Nov 2020
%平方功能%
CLC;
clearall;
关闭all;
t = 0:0.01:2;
x = sin(2*pi*t);
子图(2,1,1);
plot(t,x,'G');
xlabel('时间');
ylabel('振幅');
标题(“正方形信号318126512095');
子图(2,1,2);
stem(t,x,'r');
xlabel('时间');
ylabel('振幅');
标题('square sequence 318126512095');
2条评论
Vedanta Mohapatra
Vedanta Mohapatra on 1 Oct 2021
您必须使用信号来产生某种方波

登录发表评论。

标签

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!