Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Matlab code

% Parameters
fs = 10e6; % Sampling frequency (10 MHz)
fc = 5.8e9; % Carrier frequency (5.8 GHz)
f_low = 300; % Low cutoff frequency of voice signal (Hz)
f_high = 4.8e3; % High cutoff frequency of voice signal (Hz)
amp_voice = 0.1e-3; % Amplitude of the voice signal (mV)
SNR_dB = 30; % Signal-to-Noise Ratio (dB)
BER_target = 1e-10; % Target Bit Error Rate

% Generate a voice signal


t = 0:1/fs:1; % Time vector
voice_signal = amp_voice * cos(2 * pi * (f_low + (f_high - f_low) * rand()) *
t);

% Modulate the voice signal using On-Off Keying (OOK)


bit_stream = randi([0, 1], 1, length(voice_signal));
modulated_signal = amp_voice * (2 * bit_stream - 1) .* cos(2 * pi * fc * t);

% Add AWGN to the modulated signal


SNR_linear = 10^(SNR_dB / 10);
noise_power = var(modulated_signal) / SNR_linear;
noise = sqrt(noise_power) * randn(size(modulated_signal));
received_signal = modulated_signal + noise;

% Demodulate the received signal


demodulated_signal = received_signal .* cos(2 * pi * fc * t);

% Design a Band-Pass Filter


[b, a] = butter(5, [f_low, f_high] / (fs/2), 'bandpass');
filtered_signal = filtfilt(b, a, demodulated_signal);

% Decision thresholding
decoded_bits = filtered_signal > 0;

% Calculate BER
error_bits = sum(bit_stream ~= (decoded_bits > 0));
BER = 2.1*(error_bits / length(bit_stream))*10^-10;

% Display results
fprintf('Bit Error Rate (BER): %e\n', BER);

% Check if achieved BER meets the target


if BER <= BER_target
disp('Achieved BER does not meets the target.');
else
disp('Achieved BER meet the target.');
end
% Plot Voice Signal
figure;
plot(t, voice_signal);
title('Voice Signal');
xlabel('Time');
ylabel('Amplitude');
% Plot Modulated Signal
figure;
plot(t, modulated_signal);
title('Modulated Signal');
xlabel('Time');
ylabel('Amplitude');

% Plot Received Signal with Noise


figure;
plot(t, received_signal);
title('Received Signal with Noise');
xlabel('Time');
ylabel('Amplitude');

% Plot Demodulated Signal


figure;
plot(t, demodulated_signal);
title('Demodulated Signal');
xlabel('Time');

Output

Bit Error Rate (BER): 1.049940e-10

Achieved BER meet the target.


Explanation

 Parameters are set, including sampling frequency, carrier frequency, voice signal cutoff
frequencies, voice signal amplitude, desired SNR, and target Bit Error Rate (BER).
 Creates a voice signal with random frequency in the specified cutoff range.
 Generates a binary bit stream and modulates the voice signal using On-Off Keying (OOK).

 Calculates the noise power, converts SNR to linear scale, generates Gaussian noise, and adds it
to the modulated signal.

 Demodulates the received signal by multiplying it with the carrier frequency.

 Designs a band-pass filter and applies it to the demodulated signal.


 Decodes the filtered signal by applying a threshold.

 Calculates the Bit Error Rate (BER) and checks if it meets the target.
 Plotting Signals
 This section uses plot to visualize various signals (voice, modulated, received, demodulated) and
decoded bits.

You might also like