Assertion to check signal transition at the posedge of clock - system-verilog-assertions

I want to do an assertion which checks for the transition of a signal only on the positive edge of the clock. If the signal changes other than the positive edge it should produce an error.

Try this one:
A1: assert property (#(clock) clock == 1'b1 |=> signal == $past(signal));

Related

coverpoint to check if 2 signals are active at the same time

I am trying to write a cover point to check where 2 signals should occurring at the same time or not.
covergroup signal#(posedge clk)
signals : coverpoint (a, b){
bins on_off = {2'b11}
}
I just wanted to know whether it is the correct path of writing the cover point.
I think you meant to write coverpoint {a,b} using concatenation braces. That would work. Another thing you can do is
covergroup signal #(posedge clk);
signals : coverpoint a&b {
bins on = {1};
}
endgroup

transition false-true at initialisation OpenModelica

I have been facing some problem with Modelica initialisation. I want to simulate the initial step of a finite state machine and I would like the initial state to start from false and instantly turns to true at the beginning of the simulation.
equation
OUTPUT=active;
algorithm
when change(INPUT) then X:= not X; reinit(t,0); end when;
initial algorithm
active:=true;
Here is the code.
Variable INPUT, OUTPUT and X are all Boolean type. INPUT is a variable that makes the state changes ( from true to false and vice versa).
What the code does is to set variable active to true at the initialisation. What I would like to get is that it starts from false and it gets to true at time t=0; basically I would like to see the transition from false to true at the first instant of the simulation. Is it possible?
EDIT 2:
Looking at this issue, using initial() for the when clause solves the problem.
model Test
Boolean x(start=false) "state";
Boolean u;
Modelica.Blocks.Interfaces.BooleanOutput y;
equation
u=true;
when initial() then
x = not pre(x);
elsewhen edge(u) then
x = not pre(x);
end when;
y=x;
end Test;
Looking at the debugger of OpenModelica, first x gets the start-value false assigned, then it jumps into the when clause and sets it to true.

alternative to sample function with varying sampling range

Is there an alternative to the sample function in Openmodelica, which accepts arguments which are not of type parameter? That is, the alternative should permit the sampling of a variable range of values during a simulation.
The end goal is to create a class with which I can measure the RMS value of a real signal during a simulation. The RMS value is used as a control variable. The real signal has a continuously changing frequency so in order to have better measurements, I want to either be able to varry the sampling range continuously during simulation or discretely in some sections/periods of the oscillation.
Is it also possible to have a "running RMS" function so that the output is continuous?
In short, I would like to calculate the RMS value over a variable sampling range and the sample should only have one new term or value per iteration and not a completely new set of values.
Some possible solutions (you probably should check my math and just use them for inspiration; also check the RootMeanSquare block in the standard library which for some reason samples the Mean block):
Running RMS from beginning of time (no frequency).
model RMS
Real signal = sin(time);
Real rms = if time < 1e-10 then signal else sqrt(i_sq / time /* Assume start-time is 0; can also integrate the denominator using der(denom)=1 for a portable solution. Remember to guard the first period of time against division by zero */);
Real i_sq(start=0, fixed=true) "Integrated square of the signal";
equation
der(i_sq) = signal^2;
end RMS;
With a fixed window, f:
model RMS
constant Real f = 2*2*asin(1.0);
Real signal = sin(time);
Real rms = if time < f then (if time < 1e-10 then signal else sqrt(i_sq / time)) else sqrt(i_sq_f / f);
Real i_sq(start=0, fixed=true);
Real i_sq_f = i_sq - delay(i_sq, f);
equation
der(i_sq) = signal^2;
end RMS;
With a variable window, f (limited by f_max):
model RMS
constant Real f_max = 2*2*asin(1.0);
constant Real f = 1+abs(2*asin(time));
Real signal = sin(time);
Real rms = if time < f then (if time < 1e-10 then signal else sqrt(i_sq / time)) else sqrt(i_sq_f / f);
Real i_sq(start=0, fixed=true);
Real i_sq_f = i_sq - delay(i_sq, f, f_max);
equation
der(i_sq) = signal^2;
end RMS;
Variable time for sampling in synchronous Modelica: https://trac.modelica.org/Modelica/ticket/2022
Variable time for sampling in older Modelica:
when time>=nextEvent then
doSampleStuff(...);
nextEvent = calculateNextSampleTime(...);
end when;

MATLAB - Event Location fail to work?

The event location function fail in finding an easy event when solving a 4 variables system of ode. Here's the code:
options1 = odeset('RelTol',1e-5,'AbsTol',1e-9,'Events',#evento1);
[T_ode1,X_ode1,te]=ode15s(#Seno,[0 2],[0 0 0 0 0],options1);
function [y] = Seno(t,x)
%Parameters
V=20;
R=1e6;
epsilon=8.87e-12;
d=4.5e-5;
k_sp=10;
gamma1=0.04;
gamma2=0.1;
m=66e-3;
A=0.1;
omega=80;
h=3.8e-6;
l=2e-3;
N=142;
%Variable redefinition
%x=[x,xpunto,q,y,ypunto]
X=x(1);
Xp=x(2);
Q=x(3);
Y=x(4);
Yp=x(5);
%sistema eq differenziali
y(1)=Xp; %y1(1)=position1
y(2)=-(2*k_sp*X/m)-(gamma1*Xp/m)+((epsilon*2*d*h*N*l)*X*V^2/((d^2-X^2)^2))+A*sin(omega*t); %y1(2)=velocity1
y(3)=1/R*(V-Q*(d^2-X^2)/(epsilon*2*d*h*N*l)); %y1(3)=charge
y(4)=Yp; %position 2
y(5)=-gamma2*Yp; %velocity2
y=y';
end
function [condition,ends,directions] = evento1(t,y)
a=2e-6;
c=2e-6;
b=1.5e-6;
condition= [(y(1)^2)-(a+c)^2, (y(4)^2)-(y(1)+b)^2, (y(4)^2)-(y(1)-b)^2];
ends = [1, 1, 1]; % Halt integration
directions = [1, -1, 1];
end
Setting all the initial condition to 0, as you can see, the first event that the event function should find is when the tird condition when y(1) pass for 1.5e-6 (y(4) is 0). Unfortunally ode ignore that event and stop the solution when the 1st one is satisfied.
I can't see why this happen! I tryed the debugging mode and the systems properly pass across 1.5e-6 but doesn't consider it as an event (ie it doesn't start to evaluate the solution in more points near the event).
Thanks for your time and sorry for my english.
As I mentioned in the comments, you can plot your event conditions after simulating the system:
options1 = odeset('RelTol',1e-5,'AbsTol',1e-9,'Events',#evento1);
[T_ode1,X_ode1,te] = ode15s(#Seno,[0 2],[0 0 0 0 0],options1);
a = 2e-6;
c = 2e-6;
b = 1.5e-6;
y = X_ode1;
condition = [y(:,1).^2-(a+c)^2 y(:,4).^2-(y(:,1)+b).^2 y(:,4).^2-(y(:,1)-b).^2];
figure;
plot(T_ode1,condition);
hold on;
plot(T_ode1([1 end]),[0 0],'k--',te,0,'k*');
legend('Condition 1','Condition 2','Condition 3','Location','W');
xlabel('Time');
ylabel('State');
ylim([-1.8e-11 2e-12]);
This results in a plot that looks like this:
If you zoom in on the plot you'll see that the third condition (yellow) never crosses zero and thus never triggers an event. Eventually the first event (blue) crosses zero and does trigger an event. Adjusting the integration tolerances doesn't appear to change this behavior (at best the third condition might asymptotically touch, but not cross, zero). If you want the third condition to trigger an event, you'll either need to change your parameters, change the condition, change your initial conditions, or change your ODEs.
I'm not sure if or why you think the third condition should cross zero, but if the system is numerically sensitive, then you may need to compensate for this by specifying parameter more precisely or artificially biasing the point of zero crossing.

What is theory behind AWGN channel command matlab

Kindly tell me the theory behind the two commands (marked with ***) of an AWGN channel in the below shown code.
Code:
N_all = [10^3*ones(1,6) 10^3*ones(1,5)];
Eb_no = [0:2:20];
for ii=1:length(Eb_no)
N = N_all(ii);
b = (1/sqrt(2))*rand(1,N)>0.5;
ip = qpsk_new(b);
s = ip;
*** noise = 1/sqrt(2) * [randn(1,N/2)+j*randn(1,N/2)];
*** y = s+10^(-Eb_no(ii)/20)*noise;
end
The randn function in the first marked line generates complex, Gaussian-distributed (1), independent (2) samples with zero mean and unit variance. The second marked line scales those samples according to the specified signal-to-noise ratio (EB/N0) and adds (3) them to the signal.
These operations stem from the definition of AWGN:
The "G" in "AWGN" means "Gaussian".
The "W" means "white". The term "white" applied to a stochastic process means that the samples are statistically independent (or uncorrelated; but in the Gaussian case they are equivalent conditions).
The "A" is "additive", so you add the noise to the signal.