Sei sulla pagina 1di 12

Experiment No. 2 Aim : To study Frequency Shift Keying(FSK) modulator and demodulator in MATLAB.

. Apparatus Required : FSK Modulator circuit, FSK Demodulator circuit, MATLAB software. Theory : Frequency-shift keying (FSK) is a method of transmitting digital signals. The two binary states, logic 0 (low) and 1 (high), are each represented by an analog waveform. Logic 0 is represented by a wave at a specific frequency, and logic 1 is represented by a wave at a different frequency. A modem converts the binary data from a computer to FSK for transmission over telephone lines, cables, optical fiber, or wireless media. Diagrams :

Matlab Code : clc; clear all; close all; %% Message Bits to transmit. msg_bits = [1 0 1 1 0 0]; Tb = 1; % Bit Period (in seconds). %% Carrier Signal. fc_1 = 3; % Carrier Frequency for Message Bit '0'. fc_2 = 7; % Carrier Frequency for Message Bit '1'. fs = 8000; % Sampling Frequency. amp = 5; % Carrier Amplitude. %% Modulate. unipolarNRZ = []; carrierSignal = []; output_fsk = []; time_axis = []; tl = 0; for mBit = msg_bits if (mBit == 0)

[s t] = Generate_Sin(amp, fc_1, tl, tl + Tb, fs); output_fsk = [output_fsk s]; unipolarNRZ = [unipolarNRZ zeros(1,length(t))]; elseif (mBit == 1) [s t]= Generate_Sin(amp, fc_2, tl, tl + Tb, fs); output_fsk = [output_fsk s]; unipolarNRZ = [unipolarNRZ ones(1,length(t))]; end time_axis = [time_axis t]; tl = tl + 1; end %% Display Modulation Result. subplot(3,1,1); stem(0:length(msg_bits)-1, msg_bits,'b','LineWidth',2); axis([0 time_axis(end) -0.5 1.5]); title('Input Message Bits', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on; subplot(3,1,2); plot(time_axis, unipolarNRZ, 'b', 'LineWidth',2); axis([0 time_axis(end) -0.5 1.5]); title('Unipolar NRZ', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on; subplot(3,1,3); plot(time_axis, output_fsk, 'k', 'LineWidth',2); title('Output FSK', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on;

%% Demodulate. rx_bits = length(output_fsk) / (fs+1); detected_Bits = zeros(1, rx_bits); time_axis = []; tl = 0; for n = 1 : rx_bits samples = output_fsk(n * (fs+1) - (fs+1) + 1 : n*(fs+1));

[bit_0 t] = Generate_Sin(amp, fc_1, tl, tl + Tb, fs); [bit_1 t] = Generate_Sin(amp, fc_2, tl, tl + Tb, fs); if(sum(samples - bit_0) == 0) detected_Bits = [detected_Bits 0]; elseif(sum(samples - bit_1) == 0) detected_Bits = [detected_Bits 1]; end time_axis = [time_axis t]; tl = tl + 1; end %% Display Demodulation Result. figure; subplot(2,1,1); plot(time_axis, output_fsk, 'k', 'LineWidth',2); title('Received Signal', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on; subplot(2,1,2); stem(0:length(msg_bits)-1, msg_bits,'b','LineWidth',2); axis([0 time_axis(end) -0.5 1.5]); title('Detected Message Bits', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on;

Result :- Fig.1 shows the input message bits, the corresponding unipolar non-return to zero signal, the carrier signal and the transmitted Frequency Shift Keyed signal.

Fig.1

Fig. 2 shows the received Frequency Shift Keyed signal and the detected message bits.

Fig.2

The transmitted and received message bit sequence is the same. Hence, Frequency Shift Keying modulation and demodulation has been performed successfully.

Experiment No. 3 Aim : To study Phase Shift Keying(PSK) modulator and demodulator in MATLAB. Apparatus Required : PSK Modulator circuit, PSK Demodulator circuit, MATLAB software.

Theory : Phase-shift keying (PSK) is a method of digital communication in which the phase of a transmitted signal is varied to convey information. There are several methods that can be used to accomplish PSK.The simplest PSK technique is called binary phase-shift keying (BPSK). It uses two opposite signal phases (0 and 180 degrees). The digital signal is broken up timewise into individual bits (binary digits). The state of each bit is determined according to the state of the preceding bit. If the phase of the wave does not change, then the signal state stays the same (0 or 1). If the phase of the wave changes by 180 degrees -- that is, if the phase reverses -- then the signal state changes (from 0 to 1, or from 1 to 0). Diagrams :

Matlab Code : clc; clear all; close all; %% Message Bits to transmit. msg_bits = [1 0 1 1 0 0]; Tb = 1; % Bit Period (in seconds). %% Carrier Signal. fc = 3; % Carrier Frequency. fs = 8000; % Sampling Frequency. amp = 5; % Carrier Amplitude. %% Modulate. unipolarNRZ = []; carrierSignal = []; output_psk = []; time_axis = []; tl = 0; for mBit = msg_bits if (mBit == 0) [s t] = Generate_Sin(amp, fc, tl, tl + Tb, fs); output_psk = [output_psk s]; unipolarNRZ = [unipolarNRZ zeros(1,length(t))];

elseif (mBit == 1) [s t]= Generate_Cos(amp, fc, tl, tl + Tb, fs); output_psk = [output_psk s]; unipolarNRZ = [unipolarNRZ ones(1,length(t))]; end time_axis = [time_axis t]; tl = tl + 1; end

%% Display Modulation Result. subplot(3,1,1); stem(0:length(msg_bits)-1, msg_bits,'b','LineWidth',2); axis([0 time_axis(end) -0.5 1.5]); title('Input Message Bits', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on; subplot(3,1,2); plot(time_axis, unipolarNRZ, 'b', 'LineWidth',2); axis([0 time_axis(end) -0.5 1.5]); title('Unipolar NRZ', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on; subplot(3,1,3); plot(time_axis, output_psk, 'k', 'LineWidth',2); title('Output PSK', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on;

%% Demodulate. rx_bits = length(output_psk) / (fs+1); detected_Bits = zeros(1, rx_bits); time_axis = []; tl = 0; for n = 1 : rx_bits samples = output_psk(n * (fs+1) - (fs+1) + 1 : n*(fs+1)); [bit_0 t] = Generate_Sin(amp, fc, tl, tl + Tb, fs);

[bit_1 t] = Generate_Cos(amp, fc, tl, tl + Tb, fs); if(sum(samples - bit_0) == 0) detected_Bits = [detected_Bits 0]; elseif(sum(samples - bit_1) == 0) detected_Bits = [detected_Bits 1]; end time_axis = [time_axis t]; tl = tl + 1; end

%% Display Demodulation Result. figure; subplot(2,1,1); plot(time_axis, output_psk, 'k', 'LineWidth',2); title('Received Signal', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on;

subplot(2,1,2); stem(0:length(msg_bits)-1, msg_bits,'b','LineWidth',2); axis([0 time_axis(end) -0.5 1.5]); title('Detected Message Bits', 'Fontsize', 14); xlabel('Time'); ylabel('Amplitude'); grid on;

Result :- Fig.1 shows the input message bits, the corresponding Unipolar non-return to zero signal, the carrier signal and the transmitted Phase Shift Keyed signal.

Fig.1

Fig. 2 shows the received Phase Shift Keyed signal and the detected message bits.

Fig.2

The transmitted and received message bit sequence is the same. Hence, Phase Shift Keying modulation and demodulation has been performed successfully. .

Potrebbero piacerti anche