Anda di halaman 1dari 24

# Studying Components of a Communication System

## 1. Generate a Random Binary Data Stream.

% Define parameters. M = 16; k = log2(M); n = 3e4; nsamp = 1; hMod = modem.qammod(M); %% Signal Source % Create a binary data stream as a column vector. x = randint(n,1); % Plot first 40 bits in a stem plot. stem(x(1:40),'filled'); title('Random Bits'); xlabel('Bit Index'); ylabel('Binary Value'); % Random binary data stream % Size of signal constellation % Number of bits per symbol % Number of bits to process % Oversampling rate % Create a 16-QAM modulator

2. Prepare to Modulate.
%% Bit-to-Symbol Mapping % Convert the bits in x into k-bit symbols. xsym = bi2de(reshape(x,k,length(x)/k).','left-msb'); %% Stem Plot of Symbols % Plot first 10 symbols in a stem plot. figure; stem(xsym(1:10)); title('Random Symbols'); xlabel('Symbol Index'); ylabel('Integer Value'); % Create new figure window.

## 3. Modulate Using 16-QAM.

%% Modulation y = modulate(modem.qammod(M),xsym); % Modulate using 16-QAM. 4. Add White Gaussian Noise. %% Transmitted Signal ytx = y; %% Channel % Send signal over an AWGN channel. EbNo = 10; % In dB

snr = EbNo + 10*log10(k) - 10*log10(nsamp); ynoisy = awgn(ytx,snr,'measured'); %% Received Signal yrx = ynoisy;

5. Create a Scatter Plot. %% Scatter Plot % Create scatter plot of noisy signal and transmitted signal on the same axes. h = scatterplot(yrx(1:nsamp*5e3),nsamp,0,'g.'); hold on; scatterplot(ytx(1:5e3),1,0,'k*',h); title('Received Signal'); legend('Received Signal','Signal Constellation'); axis([-5 5 -5 5]); % Set axis ranges hold off;

6. Demodulate Using 16-QAM. %% Demodulation % Demodulate signal using 16-QAM. zsym = demodulate(modem.qamdemod(M),yrx); 7. Convert the Integer-Valued Signal to a Binary Signal. %% Symbol-to-Bit Mapping % Undo the bit-to-symbol mapping performed earlier. z = de2bi(zsym,'left-msb'); % Convert integers to bits. % Convert z from a matrix to a vector. z = reshape(z.',numel(z),1); 8. Compute the System's BER. %% BER Computation % Compare x and z to obtain the number of errors and the bit error rate. [number_of_errors,bit_error_rate] = biterr(x,z)

## M = 16; h=modem.qammod(M); mapping=h.SymbolMapping; pt = h.Constellation;

% Number of points in constellation % Modulator object % Symbol mapping vector % Vector of all points in constellation

## 3. Annotate the Plot to Indicate the Mapping.

% Include text annotations that number the points text(real(pt)+0.1,imag(pt),dec2bin(mapping)); axis([-4 4 -4 4]); % Change axis so all labels fit in plot.

Now we will switch over to the qpsk modulation technique. Data must be first selected
We have assumed that the sampling frequency is 8 times that of signal stream. 1. Nsamp=8;

number of symbols over which we have to work is now assumed let us take it as 100; 2. Numsymb=100;

Since we are talking about the qpsk technique we have to use two bits per symbol that means the four points in the constellation diagram; 3. M=4;

Now our emphasis is to design a system which generates a random stream of numbers which when called generate pattern of itself for this we have to use the function R1=randstream.getdefaultstream 4. R=randstream('mt19937ar', 'Seed', 12345)

## Generating Random Information Symbols

Now we wil generate the data stream of information symbols fro 0 to M-1; 5. r=randi(R,[0 M-1],Numsymb,1);

## Phase Modulating the Data

Use MODEM.PSKMOD to modulate the data using QPSK modulation and Gray encoding. 7. H=modem.pskmod(M,M,phaseoffset,pi/4,Symbolorder,Gray);

Upsample the symbols to a sampling rate 8 times the carrier frequency using RECTPULSE 8. 9. mi=modulate(H,r); mi=rectpulse(mi,nsamp);

## Creating the Noisy Signal

Then use AWGN to add noise to the transmitted signal 11. 12. b=awgn(mi,snr,measured,R,db); h2=scatterplo(b);

## Recovering Information from the Transmitted Signal

Use INTDUMP to downsample to the original information rate. 13. 14. 15. 16. h3=modem.pskdemod(M,M,phaseoffset,pi/4,symbolorder,Gray); h4=intdump(b,nsamp); h5=demodulate(h3,h4); h6=stem(h5(1:10),filled);

## Comparing Original Message to Demodulated Message

17. [bits in error , error rate]=biterr(r,h5);

Analog modulation
Representing Analog Signals
First decide the frequency of the carrier frequency and modulating signal 1. Fs=8000; 2. Fc=200; Now we have to create a time vector that is a representation of sampled frequency components of Fs; 3. t=[0:0.1*Fs]/Fs; Let us take a modulating signal given as 4. x=sin(2*pi*t); We will use the ammod function to modulate the x; 5. a1=ammod(x,Fc,Fs); 6. figure; % Plot x on top. subplot(2,1,1); plot(t,x); subplot(2,1,2); plot(t,y) % Plot y below.

## Analog Modulation Example

Let us take sample frequency and the carrier frequency 1. Fs=100; 2. Fc=10; Our emphasis is to create a time vector 3. t=[0:0.1*Fs]/Fs; We will generate a message signal based on these time vectors. 4. x=sin(2*pi*t); Let us use the phase modulation technique to modulate the message signal for that we have to consider the phase difference that we want to create: 5. Phase=pi/4; 6. y=pmmod(x,Fc,Fs,phase); Now add white gaussian noise to the modulated signal 7. yx=awgn(y,10,measured,90); The noisy signal is received at the otherend and then demodulated 8. yr=pmdemod(yx,Fc,Fs,phase);

## Plot the original and recovered signals.

9. 10. 11. Figure; plot(t,x,k*,t,yr,--); legend('Original signal','Recovered signal');