How to generate a BPSK signal

76 次查看(过去 30 天)
bpsk signal with carrier frequency 20Mhz,bandwidth 2MHz and which is sampled at 80MHz

采纳的回答

Chandresh Vora
Chandresh Vora 2021-7-13
% Generate BPSK signal with carrier frequency 20Mhz, bandwidth 2MHz
% and which is sampled at 80MHz
% Set up
% Specified parameters
M = 2; % Modulation order (BPSK)
Fc = 20e6; % Carrier frequency, Hz
Fb = 2e6; % Bit (baud) rate, bps OR bandwidth, Hz. For BPSK, bandwidth = bit rate
Fs = 4*Fc; % Sampling frequency, Hz
% Assumed & derived parameters
nData = 1000; % Number of bits
Ts = 1/Fs; % Sample time, sec
Td = nData/Fb; % Time duration, sec
spb = Fs/Fb; % Samples per bit
fSpan = 4; % Filter span in symbols
% Visualize the spectrum of baseband BPSK & modulated carrier
specAn1 = dsp.SpectrumAnalyzer("SampleRate", Fs, "Method","Filter bank",...
"AveragingMethod","Exponential","Title", "Pulse Shaped Baseband BPSK");
specAn2 = dsp.SpectrumAnalyzer("SampleRate", Fs, "Method","Filter bank",...
"AveragingMethod","Exponential","Title", "BPSK Modulated Carrier");
% Transmitter
% Generate random data bits
data = randi([0 M-1],nData,1);
% Modulate the data
modData = real(pskmod(data,M));
% Pulse shape & upsample to match carrier's sampling rate. Pulse shaping is
% used to reduce intersymbol interference and to reduce spectral width of
% the modulated signal.
txFilter = comm.RaisedCosineTransmitFilter("FilterSpanInSymbols",fSpan,...
"OutputSamplesPerSymbol",spb);
txfilterOut = txFilter(modData);
specAn1(txfilterOut);
% Multiply modulated & pulse shaped signal with carrier
sine = dsp.SineWave("Frequency",Fc,"SampleRate",Fs,"ComplexOutput",false,...
"SamplesPerFrame",Td/Ts);
carrier = sine();
txSignal = txfilterOut .* carrier;
specAn2((txSignal));
% Receiver
% Multiply received signal with carrier
rxSignal = txSignal .* conj(carrier);
% Low pass match filter to account for pulse shaping
rxFilter = comm.RaisedCosineReceiveFilter("FilterSpanInSymbols",fSpan,...
"InputSamplesPerSymbol",spb,"DecimationFactor",spb);
rxFilterOut = rxFilter(rxSignal);
% Demodulate
dataOut = pskdemod(rxFilterOut,M);
% Each of the Tx and Rx filters introduces a delay of fSpan/2 symbols, for
% a total delay of fSpan symbols (= bits for BPSK). Delay received bits by
% fDelay for accurate comparison with transmitted bits.
fDelay = fSpan;
[numErr, ber] = biterr(data(1:nData-fDelay),dataOut(fDelay+1:nData))
  1 个评论
Idin Motedayen-Aval
编辑:Idin Motedayen-Aval 2024-5-30
Note: dsp.SpectrumAnalyzer will be removed in a future release (it's on a deprecation path).
You can simply replace "dsp.SpectrumAnalyzer" with "spectrumAnalyzer" in the above code, and everything will work as expected.

请先登录,再进行评论。

更多回答(3 个)

John BG
John BG 2016-2-8
You can do it manually, starting from scratch as in the MATLAB examples found when searching 'signals generation' > Waveform Generation
OR
you can use already defined classes to build analogue and digitally modulated signals, search for 'Digital Baseband Modulation': MATLAB help example code
% Create binary data symbols
data = randi([0 1], 96, 1);
% Create a BPSK modulator System object
hModulator = comm.BPSKModulator;
% Change the phase offset to pi/16
hModulator.PhaseOffset = pi/16;
% Modulate and plot the data
modData = step(hModulator, data);
scatterplot(modData)
When building communication systems SIMULINK is really useful. Open Simulink from MATLAB with command 'simulink'.
SIMULINK has blocks already defined for any of the basic digital modulations. In MATLAB help search for 'PM Modulation'.
In SIMULINK open the Communications System Toolbox > Digital Baseband Modulation > PM: take your pick of BPSK modulation.
Even more useful is the SIMULINK set of related examples, among them, you can start for instance with commandapteq.m
Search with this demo name to directly open the example. In this example turning QPSK into BPSK is easy.
If you find this answer helpful, please click on the thumbs-up vote link above, thanks in advance
John

aaniket
aaniket 2023-10-29
% Generate BPSK signal with carrier frequency 20Mhz, bandwidth 2MHz
% and which is sampled at 80MHz
% Set up
% Specified parameters
M = 2; % Modulation order (BPSK)
Fc = 20e6; % Carrier frequency, Hz
Fb = 2e6; % Bit (baud) rate, bps OR bandwidth, Hz. For BPSK, bandwidth = bit rate
Fs = 4*Fc; % Sampling frequency, Hz
% Assumed & derived parameters
nData = 1000; % Number of bits
Ts = 1/Fs; % Sample time, sec
Td = nData/Fb; % Time duration, sec
spb = Fs/Fb; % Samples per bit
fSpan = 4; % Filter span in symbols
% Visualize the spectrum of baseband BPSK & modulated carrier
specAn1 = dsp.SpectrumAnalyzer("SampleRate", Fs, "Method","Filter bank",...
"AveragingMethod","Exponential","Title", "Pulse Shaped Baseband BPSK");
specAn2 = dsp.SpectrumAnalyzer("SampleRate", Fs, "Method","Filter bank",...
"AveragingMethod","Exponential","Title", "BPSK Modulated Carrier");
% Transmitter
% Generate random data bits
data = randi([0 M-1],nData,1);
% Modulate the data
modData = real(pskmod(data,M));
% Pulse shape & upsample to match carrier's sampling rate. Pulse shaping is
% used to reduce intersymbol interference and to reduce spectral width of
% the modulated signal.
txFilter = comm.RaisedCosineTransmitFilter("FilterSpanInSymbols",fSpan,...
"OutputSamplesPerSymbol",spb);
txfilterOut = txFilter(modData);
specAn1(txfilterOut);
% Multiply modulated & pulse shaped signal with carrier
sine = dsp.SineWave("Frequency",Fc,"SampleRate",Fs,"ComplexOutput",false,...
"SamplesPerFrame",Td/Ts);
carrier = sine();
txSignal = txfilterOut .* carrier;
specAn2((txSignal));
% Receiver
% Multiply received signal with carrier
rxSignal = txSignal .* conj(carrier);
% Low pass match filter to account for pulse shaping
rxFilter = comm.RaisedCosineReceiveFilter("FilterSpanInSymbols",fSpan,...
"InputSamplesPerSymbol",spb,"DecimationFactor",spb);
rxFilterOut = rxFilter(rxSignal);
% Demodulate
dataOut = pskdemod(rxFilterOut,M);
% Each of the Tx and Rx filters introduces a delay of fSpan/2 symbols, for
% a total delay of fSpan symbols (= bits for BPSK). Delay received bits by
% fDelay for accurate comparison with transmitted bits.
fDelay = fSpan;
[numErr, ber] = biterr(data(1:nData-fDelay),dataOut(fDelay+1:nData))

Mohd
Mohd 2024-9-13,10:57
% MATLAB code for Amplitude Shift Keying (ASK)
% Idea behind the plot is very easy.
% This code can be mainly divided into four parts:
% part 1: Defining the necceassy parameters and time for the x- axis;
% part 2: Defining the function to draw the carrier wave;
% part 3: Applying the logic for the ASK, PSK, and FSK;
% part 4: Finally plotting the graph;
clc;
clear;
close all;
% Parameters
bit_stream = [0 0 1 1 0 1 0 0 1]; % Binary data stream
fs = 100; % Sampling frequency
bit_duration = 1; % Duration of each bit
t = 0:1/fs:bit_duration-1/fs; % Time vector for one bit
fc = 5; % Carrier frequency
% Time axis for entire signal
t_total = 0:1/fs:bit_duration*length(bit_stream)-1/fs;
% Carrier signal for visualization
carrier_signal = repmat(cos(2*pi*fc*t), 1, length(bit_stream));
% ASK Signal
ask_signal = [];
for i = 1:length(bit_stream)
if bit_stream(i) == 1
ask_signal = [ask_signal cos(2*pi*fc*t)]; % Transmit carrier for '1'
else
ask_signal = [ask_signal 0*cos(2*pi*fc*t)]; % No signal for '0'
end
end
% Plot Carrier Signal
figure;
subplot(2, 1, 1); % First plot in a 2x1 grid
plot(t_total, carrier_signal, 'LineWidth', 2.0);
title('Carrier Signal by ');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Plot ASK Signal
subplot(2, 1, 2); % Second plot in a 2x1 grid
plot(t_total, ask_signal, 'LineWidth', 2.0);
title('Amplitude Shift Keying (ASK)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

标签

Community Treasure Hunt

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

Start Hunting!

Translated by