quartus2输出msk调制解调的可仿真代码
时间: 2024-05-06 09:17:09 浏览: 52
以下是一个简单的基于Quartus II的MSK调制解调器仿真代码:
```verilog
module msk_mod_demod(
input clk,
input rst,
input [7:0] data_in,
output reg ms_out
);
// Modulation parameters
parameter Fc = 10e6; // Carrier frequency
parameter Fs = 50e6; // Sampling frequency
parameter T = 1/Fs; // Sampling period
parameter baud = 100e3;// Bit rate
parameter Tb = 1/baud; // Bit duration
parameter Bt = 0.5; // BT product (Gaussian filter bandwidth)
parameter h_len = 11; // Gaussian filter length
// Modulation variables
reg [31:0] phi_acc; // Phase accumulator
reg [31:0] phi_last; // Last phase value
reg [31:0] phi_diff; // Phase difference
reg [31:0] mod_out; // Modulated output
reg [h_len-1:0] h; // Gaussian filter coefficients
reg [h_len-1:0] h_last; // Last Gaussian filter coefficients
reg [31:0] s_in; // Input shift register
reg [31:0] s_out; // Output shift register
reg [31:0] s_last; // Last output shift register
reg [h_len-1:0] s_tap; // Gaussian filter tap
reg [31:0] demod_out; // Demodulated output
// Modulation constants
localparam phi_max = 2**32 - 1; // Maximum phase value
localparam phi_inc = round(Fc*T*2**32); // Phase increment
localparam phi_wrap = round(Fs*T*2**32); // Phase wrap-around threshold
localparam h_norm = $floor((1<<(h_len-1))*exp(-Bt*Bt/(2*Tb*Tb))/sqrt(2*$pi*Bt*Bt/Tb)); // Gaussian filter normalization factor
// Modulation initialization
initial begin
phi_acc <= 0;
phi_last <= 0;
phi_diff <= 0;
mod_out <= 0;
h <= {32{1'h0}};
h_last <= h;
s_in <= 0;
s_out <= 0;
s_last <= s_out;
s_tap <= h;
demod_out <= 0;
end
// Modulation
always @(posedge clk) begin
if (rst) begin
phi_acc <= 0;
phi_last <= 0;
phi_diff <= 0;
mod_out <= 0;
h <= {32{1'h0}};
h_last <= h;
s_in <= 0;
s_out <= 0;
s_last <= s_out;
s_tap <= h;
end else begin
phi_last <= phi_acc;
phi_acc <= phi_acc + phi_inc;
if (phi_acc >= phi_wrap) phi_acc <= phi_acc - phi_wrap;
phi_diff <= phi_acc - phi_last;
mod_out <= $signed(data_in) * $sin(2*$pi*Fc*T*phi_diff);
s_in <= {s_in[31:1], mod_out};
s_out <= s_in * s_tap;
s_last <= s_out;
ms_out <= $signed(s_out[31]);
end
end
// Gaussian filter
always @(posedge clk) begin
if (rst) begin
h <= {32{1'h0}};
h_last <= h;
s_tap <= h;
end else begin
h_last <= h;
for (int i = 0; i < h_len; i = i + 1) begin
if (i == 0) h[i] <= $signed(s_last[31]);
else h[i] <= h_last[i-1];
end
s_tap <= h;
end
end
// Demodulation
always @(posedge clk) begin
if (rst) begin
s_out <= 0;
s_last <= s_out;
demod_out <= 0;
end else begin
s_last <= s_out;
demod_out <= $signed(s_out[31]) * $sin(2*$pi*Fc*T*phi_diff);
end
end
endmodule
```
这个代码实现了一个基于高斯滤波的MSK调制解调器,可以通过Quartus II进行仿真。请注意,代码中的参数和变量设置是为了简单起见,并且可能需要根据具体应用进行修改。
阅读全文