필터 지우기
필터 지우기

Random pulse generator

조회 수: 21 (최근 30일)
Néstor Monedero
Néstor Monedero 2011년 10월 19일
댓글: sneha j 2021년 5월 3일
Hello,
I'm new in Simulink and i trying to make a pulse random generator. Pulses have amplitude (+10 & -10) and width (1 ms). The signal has to be non periodic, i mean, pulses has to appear by a random series. how can i do it? I apprecitate any help. The begining of my project depend of this signal.
Thanks. Néstor.
  댓글 수: 3
Néstor Monedero
Néstor Monedero 2012년 10월 29일
Hi Azzi, The maximale distance between two impulses may be 2 ms, for example. The idea is that: the distance is as close as possible. I achieve to do this pulse random generator with these blocks: A uniform random number, a matlab function that convert this pulses in other with amplitude +1/-1.
If you need more information, please, give me question. Néstor
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 29일
Check the second image (modified)
set the Amplitude of the pulse generator to 2 and substract 1

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 27일
편집: Azzi Abdelmalek 2012년 10월 27일
use this block
the function is
function y = fcn(u)
%#codegen
id=rand(1)
if id>0.5 & u==0
y=1
else
y=0
end
or easier
%

추가 답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 10월 19일
Go to Simulink Sources library, there is the Random Number block and the Uniform Random Number block.
The output of the Uniform Random Number is between 0 and 1, so you'll need to use Relational Operator block to compare it with constant such as 0.1 and 0.9, and then use Switch block to output the +10 or -10 or 0 pulse value.
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2011년 10월 21일
You can compare the random number with a constant, e.g. 0.9 and then add a zero-order holder block.
Fangjun Jiang
Fangjun Jiang 2011년 11월 28일
See update.

댓글을 달려면 로그인하십시오.


Néstor Monedero
Néstor Monedero 2011년 11월 28일
I try to simulate random pulse generator using "uniform random number" plus a Matlab function. The code of the Matlab function is:
function y = fcn(u)
%#codegen
n=length(u);
y=[1:n];
for i=1:n
if(u(i)<-0.9)
y(i)=-1;
end
if(u(i)>0.9)
y(i)=1;
else
y(i)=0;
end
end
The result is not what i want. I only obtain pulses with positive amplitude. I need two kind of pulses: positive and negative. what i am doing wrong? any idea? Please i need to build this signal to advanced in my project. Thanks in advance. Néstor.
  댓글 수: 2
sneha j
sneha j 2021년 5월 3일
hi, there is a bug in ur code.
In the case that u(i)<-0.9, y(i) sets to -1 in the first if-block.
But wen it executes the 2nd if-block - if gets overwritten by y(i)=0 as u(i)<0.9, so it executes the else part of the block.
U need to club the the first if block with the 2nd if-else block into one if block as follows:
if(u(i)<-0.9)
y(i)=-1;
else if(u(i)>0.9)
y(i)=1;
else
y(i)=0;
end
Hope it works well.
sneha j
sneha j 2021년 5월 3일
hi Nestor, sorry i jus realised that the else if block doesnt work, so here is a workaround:
if(u<-0.5)
y=-10;
else
y=0;
end
if(u>0.5)
y=10;
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by