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/ 2
% Parameters
Fs = 10000; % Sampling Frequency
Fc = 1000; % Carrier Frequency bitRate = 1; % Bit Rate (Bits per second) bitDuration = 1/bitRate; % Duration of one bit numBits = 8; % Number of bits to transmit time = 0:1/Fs:bitDuration*numBits - 1/Fs; % Time vector % Generate random binary data data = randi([0 1], 1, numBits); % Binary data (0s and 1s) % Modulation carrier = cos(2 * pi * Fc * time); % Carrier signal askSignal = zeros(1, length(time)); % Initialize ASK signal % Create ASK signal for i = 1:numBits if data(i) == 1 askSignal((i-1)*Fs*bitDuration+1:i*Fs*bitDuration) = carrier((i-1)*Fs*bitDuration+1:i*Fs*bitDuration); else askSignal((i-1)*Fs*bitDuration+1:i*Fs*bitDuration) = 0; end end % Plot the modulated ASK signal figure; subplot(3,1,1); stairs(repmat(data, Fs*bitDuration, 1)); % Plot binary data title('Binary Input Data'); xlabel('Time (s)'); ylabel('Amplitude'); subplot(3,1,2); plot(time, askSignal); title('ASK Modulated Signal'); xlabel('Time (s)'); ylabel('Amplitude'); % Add noise to the ASK signal (for testing demodulation) noisySignal = askSignal + 0.5 * randn(1, length(askSignal)); % Adding Gaussian noise % Plot the noisy signal subplot(3,1,3); plot(time, noisySignal); title('Noisy ASK Signal'); xlabel('Time (s)'); ylabel('Amplitude'); % Demodulation demodulatedSignal = zeros(1, numBits); % Initialize demodulated signal for i = 1:numBits segment = noisySignal((i-1)*Fs*bitDuration+1:i*Fs*bitDuration); % Extract each bit duration energy = sum(segment .* carrier((i-1)*Fs*bitDuration+1:i*Fs*bitDuration)); % Calculate energy of the received signal if energy > 0.5 % Threshold decision (modify this based on noise level) demodulatedSignal(i) = 1; else demodulatedSignal(i) = 0; end end % Display demodulated bits disp('Original Data:'); disp(data); disp('Demodulated Data:'); disp(demodulatedSignal); % Plot the demodulated data figure; stairs(repmat(demodulatedSignal, Fs*bitDuration, 1)); title('Demodulated Data'); xlabel('Time (s)'); ylabel('Amplitude');