In general you would have been better served if you also showed the time domain waveforms so we could look for unusual artifacts. However, you made two classic mistakes, and you will probably get better results if you fix those.
1. You are generating a sinusoid at a frequency that is much higher than any input frequency and yet you have no $bound_step function to prevent aliasing/Nyquist problems.
2. You are abruptly changing the phase and yet you have no transition function to control the transition times.
In addition, your initialization of phase to 0 is unnecessary, it defaults to 0.
You might try something like this:
Code:module DPSKModulator(in, clk, out);
input in; electrical in;
input in; electrical clk;
output out; electrical out;
parameter real Amplitude = 0.2;
parameter real Freq = 4G;
parameter real vth = 0.6; //Threshold voltage
parameter real offset = 0;
real phase;
analog begin
@(cross(V(clk) - vth, +1)) begin
if (V(in) > vth)
phase = phase + `M_PI;
end
V(out) <+ Amplitude*sin(2*`M_PI*Freq*$abstime + transition(phase, 0, 1n))+offset;
$bound_step(0.1/Freq);
end
endmodule
-Ken