MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">ここ</a>」をクリックしてください。

0

Generate Square Wave

Onur Öçalan さんによって質問されました 2011 年 12 月 16 日
Hi everybody;
I want to create a rectangular wave with a specific function. For example,
the wavelength of the wave = 20 milliseconds
the wave width = 1.2 milliseconds
How do I do with Matlab ?
Please help...
Thanks.

  3 件のコメント

Dr. Seis
2011 年 12 月 17 日
I am a bit confused as to what you are calling the "wavelength" and "width" of the wave... in my mind the wavelength should be an equivalent way of saying the width of a single wave. See my answer below for providing a "wavelength" equal to 1.2 milliseconds, a "signal length" of 20 milliseconds, and an amplitude of 0.75.
Onur Öçalan 2011 年 12 月 17 日
http://imageshack.us/photo/my-images/714/20111217100355.jpg/
I want just like it...
Thanks.
Onur Öçalan 2011 年 12 月 17 日
And I cann't put this value to Nidaq 6008 digital out line ??

サインイン to comment.

3 件の回答

Paulo Silva
回答者: Paulo Silva
2011 年 12 月 16 日

Here's my crazy way to do it, I'm assuming some values for example the sampling time. This way doesn't require any toolboxes, another way to do it easily would be to use the Control System Toolbox™ gensig function that I usually use.
l=20e-6;
w=1.2e-6;
Ts=1e-9;
t=0:Ts:l; %generate the time vector
s=0:Ts:w; %generate a piece of the wave, the one with zeros
s0=s*0;
%generate another piece of the wave, the one with ones
s1=s*0+1;
s=[s s1]; %combine them for one period of the wave
s=repmat(s,1,round(l/(2*w)+1)); %create the entire wave from that first piece
%view the wave
plot(t,s((1:size(t,2))))
ylim([-0.5 1.5])

  3 件のコメント

Sean de Wolski
2011 年 12 月 16 日
certainly works!
Onur Öçalan 2011 年 12 月 17 日
http://imageshack.us/photo/my-images/714/20111217100355.jpg/
I want just like it...
Thanks.
Paulo Silva
2011 年 12 月 18 日
l=20e-6;
w=1.2e-6;
Ts=1e-9;
t1=0:Ts:w;
t0=w+Ts:Ts:l-Ts;
s1=ones(size(t1));
s0=zeros(size(t0));
s=[s1 s0];
N=2; %How many repetitions of the wave
ss=repmat(s,1,N);
t=0:Ts:N*l-Ts;
plot(t,ss)
ylim([-0.5 1.5])

サインイン to comment.


Dr. Seis
回答者: Dr. Seis
2011 年 12 月 17 日

signal_length = 20e-6; % length of signal in seconds
wave_length = 1.2e-6; % wavelength of rectangle pulse in seconds
amplitude = 0.75; % amplitude of wave
dt = 1e-9; % time increment in seconds
time = 0:dt:signal_length; % time samples in seconds
% Define the rectangle signal timeseries
rectsignal = sign(sin(2*pi*time/wave_length)).*ones(size(time))*amplitude;
% Plot the timeseries
plot(time,rectsignal,'r-');

  2 件のコメント

Dr. Seis
2011 年 12 月 17 日
The above basically provides a squared-off sine wave. Is this what you want?
Onur Öçalan 2011 年 12 月 17 日
http://imageshack.us/photo/my-images/714/20111217100355.jpg/
I want just like it...
Thanks.

サインイン to comment.


Dr. Seis
回答者: Dr. Seis
2011 年 12 月 18 日

This should work:
dt = 1e-9; % time increment (in seconds)
maxtime = 200e-6; % maximum length of signal (in seconds)
time = 0:dt:maxtime; % time samples (in seconds)
wavelength = 20e-6; % distance between beginning of each pulse
wavewidth = 1.2e-6; % width of each pulse
rectpulse = ones(1,round(wavewidth/dt)); % Define width of rectangle pulse
operator = zeros(size(time)); % Set operator to zeros
operator(mod(time,wavelength)==0) = 1; % Place 1 at each pulse location
rectsignal = conv(operator,rectpulse); % Convolve rectpulse w/ operator
rectsignal = rectsignal(1,1:length(time)); % Remove any extra traces
plot(time,rectsignal); % Plot the signal

  0 件のコメント

サインイン to comment.



Translated by