Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear all
- close all
- %vm = input('Enter Amplitude (Message) = ');
- %vc = input('Enter Amplitude (Carrier) = ');
- fM = input('Enter Message frequency = ');
- fC = input('Enter Carrier frequency = ');
- deviation = input('Enter Freq. deviation = ');
- % The number of bits to send - Frame Length
- N = 8;
- % Generate the bit stream
- str = input ("Give me some text: ", "s");
- message = (dec2bin (uint8 (str), N) - "0").'(:).';
- disp (message);
- %fC = 100e3;
- %fM = 10e3;
- %deviation = 40e3;
- fs = 100 * fC;
- t = [0 : 1/fs : length(message) * 1/fM];
- % t is too large because the endpoint is included.fs
- % ugly fix to address this
- t = t(1:end-1);
- % Those are prototype-waveforms for a low and a high bit.
- t_prototype = t(1:end/length(message));
- low_prototype = sin(2*pi*(fC-deviation)*t_prototype);
- high_prototype = sin(2*pi*(fC+deviation)*t_prototype);
- % Piece together protoypes to modulated message
- y = [];
- for i = message
- if i == 0
- y = [y low_prototype];
- else
- y = [y high_prototype];
- endif;
- end
- upsampling_factor = fs/fM ;
- message_resampled = repmat(message, upsampling_factor, 1)(:)' - 0.5;
- subplot(4,1,1);
- plot(t, message_resampled, 'linewidth', 1.5, '-r');
- refresh;
- xlabel('Time [s]');
- ylabel('Amplitude [V]');
- title('Message Signal waveform');
- grid on;
- axis tight;
- carrier = sin(2*pi*fC*t);
- subplot(4,1,2);
- plot(t,carrier);
- xlabel('Time [s]');
- ylabel('Amplitude [V]');
- title('Carrier Signal waveform');
- grid on;
- axis tight;
- subplot(4,1,3);
- plot(t,y);
- xlabel('Time [s]');
- ylabel('Amplitude [V]');
- title('FM Signal waveform');
- grid on;
- axis tight;
- Nsamps = length (y);
- y_fft = abs (fft (y)); %Retain Magnitude
- y_fft = y_fft(1:Nsamps/2); %Discard Half of Points
- f_fft = fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot
- subplot (4,1,4);
- plot(f_fft, y_fft, 'linewidth', 1.5, '-g');
- xlim ([0 2e5]);
- ylabel ('Amplitude');
- xlabel ('Frequency (Hz)');
- title ('Spectrum plot of the FSK modulated signal');
- grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement