BPSK modulator model

At some point I needed to have an ideal Verilog-A BPSK modulator:

BPSK modulation example

Less words, more code:

`include "constants.vams"</span>
`include "disciplines.vams"
module SimpleModulator(in, out);
input in;
output out;
electrical in;
electrical out;
parameter real Amplitude = 0.2;   //Амплитуда нашего сигнала
parameter real Freq = 1G;         //Несущая частота
parameter real vth = 0.6;         //Порог срабатывания 0->1
parameter real offset = 0;        //Постоянная составляющая
real phase;                       //фаза выходного сигнала
analog begin
@(initial_step) phase = 0;
@(cross(V(in) - vth, +1))
begin                       //По каждому возрастающему фронту
 phase = 3.14159265359;     //фаза 180 градусов = 1
@(cross(V(in) - vth, -1))
begin                       //По каждому спадающему фронту
phase = 0;                  //фаза 0 градусов = 0</span>
V(out) <+ Amplitude*sin(2*3.14159265359*Freq*$abstime + phase)+offset;

In order to check how it works I pulled the rand bit generator from ahdlLib and settled the proper frequency for it.

The resulting waveform in the first picture.

Leave a Reply

Your email address will not be published.