0% found this document useful (0 votes)
9 views3 pages

Awgn

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Awgn

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

clc; clear;

% Parameters
N = 10; % Number of bits
SNR_dB = 10; % Signal-to-Noise Ratio in dB
Tb = 1; % Bit duration (seconds)
fs = 100; % Sampling frequency (Hz)
Samples_per_bit = Tb * fs;

% Generate random binary data


data = randi([0 1], 1, N);

% Map binary data to bipolar format (+1 and -1)


tx_signal = 2 * data - 1;

% Create unsampled transmitted signal


tx_signal_unsampled = kron(tx_signal, ones(1, Samples_per_bit)); % Repeat
each bit by Samples_per_bit

% Calculate noise power


SNR_linear = 10^(SNR_dB / 10); % Convert SNR from dB to linear scale
signal_power = mean(tx_signal_unsampled.^2); % Average power of transmitted
signal
noise_power = signal_power / SNR_linear; % Calculate noise power

% Generate AWGN
noise = sqrt(noise_power) * randn(1, length(tx_signal_unsampled));

% Received signal (transmitted signal + noise)


rx_signal = tx_signal_unsampled + noise;

% Matched filter (rectangular pulse matched filter)


matched_filter = ones(1, Samples_per_bit); % Define rectangular pulse
matched_filter_output = conv(rx_signal, matched_filter, 'same'); % Convolve
with 'same' to match length

% Downsample matched filter output to one sample per bit


downsampled_output =
matched_filter_output(Samples_per_bit:Samples_per_bit:end);

% Decision device (threshold at 0)


rx_data = downsampled_output > 0; % Recover binary data

% Calculate errors
num_errors = sum(rx_data ~= data);
BER = num_errors / N;

% Display results
disp(['Number of errors: ', num2str(num_errors)]);
disp(['Bit Error Rate (BER): ', num2str(BER)]);

% Create time axis in seconds


time = (0:length(tx_signal_unsampled)-1) / fs; % Time vector in seconds
% Plot transmitted and received signals
figure;

% Transmitted Signal
subplot(2, 1, 1);
plot(time, tx_signal_unsampled, 'b');
title('Transmitted Binary Baseband Signal');
xlabel('Time (seconds)');
ylabel('Amplitude');

% Received Signal
subplot(2, 1, 2);
plot(time, rx_signal, 'b');
title('Received Signal with AWGN');
xlabel('Time (seconds)');
ylabel('Amplitude');

You might also like