Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % MATLAB Script for a Binary ASK with two Amplitude Levels
- format long;
- % Clear all variables and close all figures
- clear all;
- close all;
- clc;
- % The number of bits to send - Frame Length
- N = 8;
- % Generate the bit stream
- str = input ("Give me some text: ", "s");
- bit_stream = (dec2bin (uint8 (str), N) - "0").'(:).';
- % Enter the two Amplitudes
- % Amplitude for 0 bit
- A1 = 2;
- % Amplitude for 1 bit
- A2 = 5;
- % Frequency of Modulating Signal
- f = 10e3;
- % Sampling rate - This will define the resoultion
- fs = 5e6;
- % Time for one bit
- t = [0 : 1/fs : 2/f];
- % This time variable is just for plot
- time = [];
- ASK_signal = [];
- Digital_signal = [];
- for ii = 1: 1: length(bit_stream)
- % The Original Digital Signal
- Digital_signal = [Digital_signal (bit_stream(ii)==0) * zeros(1,length(t)) + (bit_stream(ii)==1)*ones(1,length(t))];
- % The ASK Signal
- ASK_signal = [ASK_signal (bit_stream(ii)==0)*A1*sin(2*pi*f*t) + (bit_stream(ii)==1)*A2*sin(2*pi*f*t)];
- time = [time t];
- t = t + 2e-4;
- end
- % Plot the Original Digital Signal
- subplot(3,1,1);
- plot(time,Digital_signal,'r','LineWidth',2);
- xlabel('Time (bit period)');
- ylabel('Amplitude');
- title('Original Digital Signal');
- axis tight;
- grid on;
- % Plot the ASK Signal
- subplot(3,1,2);
- plot(time,ASK_signal,'LineWidth',1);
- xlabel('Time (bit period)');
- ylabel('Amplitude');
- title('ASK Signal with two Amplitudes');
- axis tight;
- grid on;
- % Plot the ASK Spectrum
- Nsamps = length(ASK_signal);
- %t1 = (1/fs)*(1:Nsamps); %Prepare time data for plot
- %Do Fourier Transform
- y_fft = abs(fft(ASK_signal)); %Retain Magnitude
- y_fft = y_fft(1:Nsamps/2); %Discard Half of Points
- f1 = fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot
- %Plot ASK in Frequency Domain
- subplot(3,1,3);
- plot(f1, y_fft, 'linewidth', 2, 'r');
- xlim([0 20e3]);
- xlabel('Frequency (Hz)');
- ylabel('Amplitude');
- title('Spectrum plot for ASK modulated Signal');
- grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement