Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ELEC 2430 Communications Theory

MatLab based Assignment

Introduction

In this laboratory session you will be putting into practice some of the theory you have learned in the 2430 lectures. There are two parts.

Part I: You will be using the Fast Fourier Transform (FFT) to translate a signal from the time domain to the frequency domain.  An FFT is a computer algorithm that is widely used to calculate the Fourier transform of a signal and has many applications in Electronic Engineering, particularly in the field of Communications and Digital Signal Processing (DSP).

The FFT allows you to calculate the discrete FT of a signal.  Therefore if the signal you wish to carry out the FFT on a continuous signal, as is the case with a voice or piece of music, you must sample the continuous signal at specific intervals in order to extract its discrete value at each point. If you were to calculate the FT of a signal with N points directly using the equation that defines the DFT, it would take around N2 computer operations.  The FFT is an extremely efficient algorithm that takes only around N log N operations.  In cases where N can run in the millions, this reduction can lead to orders of magnitude less computer operations required, reducing the run-time dramatically.  Hence the name fast!


Part II: You will simulate an AM system using MatLab and evaluate the Bit Error Rate performance when the information is transmitted over an AWGN  under different signal-to-noise  ratio  (SNR) conditions. The objectives of this  part are to understand how a digital signal is transmitted over an AWGN wireless channel using amplitude modulation (AM) and analyse the time and frequency domain responses of the AM system’s signals.

Part I [40 marks]

1- Using MATLAB to calculate the FFT of a sine wave [25 marks]

In this section, you will learn how to use MATLAB to calculate the FFT of a signal and investigate the effect of some of the parameters have on the spectrum.

% ELEC 2430 Laboratory

% MATLAB Fast Fourier Transform M-file

clear all

close all

fs = 500; % sampling frequency (must be > 2*maximum signal freq)

Ts = 1/fs; % sampling time interval

n = 100; % number of samples

t = linspace(0,n*Ts,n);

y = sin(2*pi*100*t); % time-domain signal

subplot(2,1,1);

plot(t,y); % plot time-domain signal

xlabel('t(s)');

ylabel('y(t)');

title('time-domain signal');

N = 2^16; % number of samples to use in FFT (must be > n)

% MATLAB recommends it to be a power of 2 for speed

% purposes (2^16 = 65536)

Y = abs(fft(y,N))/n; % take absolute value (FFT is complex)

% and normalise

Y = fftshift(Y); % shift from 0 -> fs to -fs/2 -> fs/2

f = fs*[-N/2:N/2-1]/N; % calculate frequency for each point

subplot(2,1,2)

%plot(f,2*Y); % plot full FFT spectra

plot(f(1+N/2:N-1),2*Y(1+N/2:N-1)) % plot positive-frequencies only

xlabel('f (Hz)');

ylabel('|Y(f)|');

title('FFT spectrum');

Task 1:

Run the .m file by clicking the green triangle icon on the menu bar or by pressing F5.

If all goes to plan you should see the following figure. If you look in the M-file, you will see a 100 Hz sine wave was generated (in the array y).  An FFT was then carried out on this resulting in the frequency spectrum displayed above.  You can see a large peak around 100 Hz suggesting that the FFT was successful (you may be wondering why it has a sinc-like shape rather than the expected impulse and you will find out soon enough).

You should now believe that our code works so we will inspect it line by line to see what is going on:

clear all

close all

These two lines of code simply delete all previous variables and close any open figures to avoid any confusion fs = 500; % sampling frequency (must be > 2*maximum signal frequency)

We then set the frequency at which we sample the signal.  In this case it is 500 Hz i.e. we will take a sample 500 times a second. To fulfil the Nyquist criterion, the sample rate must be at least twice the maximum signal frequency. Audio frequencies max out around 20 kHz and so high quality digital audio (i.e. CD’s) are sampled at around 44.1 kHz.

Ts = 1/fs; % sampling time interval

We can then calculate the interval between each sample.  In our case, we will take a sample every 1/500 = 2 ms. Page 4 of 13

n = 100; % number of samples

We then define how many samples we will take.  In this case we have 100 samples, corresponding to a time-domain signal length of 100 x 2 ms = 0.2 s which you can see in the figure above.  For a 100 Hz signal this corresponds to 20 periods. You need to make sure you have the right combination of sampling frequency and number of samples to ensure at least one whole period of your signal is analysed.  If your signal is made up of several frequency components, you need to make sure you have at least one whole period of your lowest frequency component.

t = linspace(0,n*Ts,n);

y = sin(2*pi*100*t); % time-domain signal

We then create an array of the times at which we take the samples and create the associated time-domain signal, in this case a simple 100 Hz sine wave.  Note how the sampling frequency is five times bigger than this and so fulfils the Nyquist criterion.

The next few lines just plot the time-domain signal and label the axis.  The next step is to set the number of points we are using in the FFT.

N = 2^16; % number of samples to use in FFT (must be > n)

% MATLAB recommends it to be a power of 2 for speed

% 2^16 = 65536

In this case we are using 65536 points and as it says in the code comments, the FFT algorithm performs faster if this number is a power of 2.  It must also be greater than the number of sample points. The array which holds the signal values (y) is padded with zeroes to make its length equal to N.   In order to get an impulse, we actually require an infinitely long sinusoid. By only taking N points of the sinusoid, we are effectively multiplying in the time-domain by a ‘window’.  It is above the scope here, but multiplying by a window in the time-domain, we convolve in the frequency domain with a sinc function. By making the window longer (i.e. by increasing the length of the time-domain signal) the sinc functions become more and more impulse-like.

Y = abs(fft(y,N))/n; % take absolute value (FFT is complex)

% and normalise

We then calculate the FFT of y.  The FFT function returns a complex quantity that relates to the magnitude and phase of the signal so we take the absolute value of this to plot.  We also normalise it by dividing by the sample length.

Y = fftshift(Y); % shift from 0 -> fs to -fs/2 -> fs/2

From your lectures, you should know that when you calculate the FT of a signal you end up with positive and negative frequencies.  The array MATLAB returns from the FFT function goes from 0 to fs and so we use to fftshift function to shift this so it goes from –fs/2 to fs/2.  In this example, we had a sampling frequency of 500 Hz and this is the reason the plots only extend up to 250 Hz.

f = fs*[-N/2:N/2-1]/N; % calculate frequency for each point

We then calculate the frequencies which the FFT samples correspond to. From this you should be able to see the resolution of the FFT is given by fs/N i.e. the more points we take in the FFT, the more closely spaced the frequency points are.

%plot(f,2*Y); % plot full FFT spectra

plot(f(1+N/2:N-1),2*Y(1+N/2:N-1)) % plot positive-frequencies only

Since the frequency spectra is a mirror image around 0 Hz we have redundancy and so we only need to plot the positive side.  Note that we multiply by a factor of 2 to get the correct power.  You can uncomment the top line and comment out the bottom one to plot the full spectrum showing both the positive and negative frequencies. The last few lines of the script simply add labels to the plot.

Task 2: Run the script several times to investigate the effect of the FFT parameters on the results. Investigate how the number of samples, the number of FFT points and the sampling rates affect your results. Include pictures in your report to back up your findings.

The following simple example highlights one of the ways in which FFTs can be useful.

Task 3:

Change the time-domain signal so it is given by the following (addition of two sine waves plus random noise) y = sin(2*pi*50*t) + sin(2*pi*200*t) + randn(size(t));

Run the script again and look at the time-domain signal. Can you identify the main frequency components in the signal?

Look at the frequency spectrum. Although smaller peaks are now present at all frequencies due to the noise, it is clear what the two fundamental frequencies in the signal are.

Include your results in the report.

2 The frequency domain representation of a square wave [15 marks]

So far we have just looked at the spectra of a simple sinusoid signal but in the area of digital electronics, our baseband data signal is often a bit stream i.e. a series of 1’s and 0’s.  So what does this look like in the frequency domain?

Task 4:

In your MATLAB script, create a 10 Hz square wave using the square() function and calculate the FFT. You should get something along the lines of

Answer the following questions in your report:

1) What do you notice about the harmonics that are present?

2) Does this spectra give you any clues as to why data signals made up from square waves are often ‘rounded’ (i.e. remove the sharp edges) before they are transmitted (hint: look at the bandwidth compared to the signal frequency)?

In this case, our baseband data is made up of a periodic square wave.  This couldn’t actually transmit any information and actual digital signals are in fact a random combination of ones and zeros.

Task 5:

Add the following code in your script to generate a random bit stream

dataRate = 100; % of signal (b/s)

bitPeriod = 1/dataRate; % duration of a bit

numberOfBits = 100; % number of bits in the sample

samplesPerBit = bitPeriod/Ts; % number of samples per bit

n = numberOfBits * samplesPerBit; % total number of samples

y=zeros(1,n); % create empty array to store points

data = 2*round(rand(1,numberOfBits))-1; % create NRZ random data

k=1

for i = 1:numberOfBits

for j = 1:samplesPerBit

y(k) = data(i);

k=k+1;

end

end

% these loops create the

% bit stream

Your frequency domain representation will be clearer if you plot it in decibels (20 log10). Modify your code so it does this and paste in a screen shot of the resulting time-domain and frequency spectra.

Answer the following questions in your report:

1) What do you notice about the frequencies of the nulls in the sinc-like function?

2) How does this spectrum compare to that of a periodic square wave?

Part2:- AmplitudeModulationSystem

andspectrumanalysis [60 marks]

Objectives

-     Understand  how  a  digital  signal  is  transmitted  over  an  AWGN  wireless  channel  using  amplitude modulation (AM).

-     Simulate an AM system using Matlab and evaluate its Bit Error Rate performance when the information is transmitted over an AWGN under different signal-to-noise ratio (SNR) conditions.

-     Analyse the time and frequency domain responses of the AM system’s signals.

Description

Amplitude modulation (AM) is a scheme where the amplitude of a sinusoidal carrier is changed as a function of the modulating signal.  AM systems are characterised by a relatively low bandwidth requirement but they are power inefficient compared to other modulation schemes like angle-modulation techniques.  These systems are widely used in broadcasting (AM radio and (analogue) TV broadcasting), point-to-point communications and multiplexing applications.

A simple binary AM (double sideband SC) is depicted in the following diagram.

Figure 1. DSB-SC modulation system

The above figure shows an AM system where a binary input is sampled to obtain a unipolar encoded signal.    The binary 1’s and 0’s is done by sampling each bit using a sampling frequency to then represent the unipolar encoded signal by a given voltage level for a binary 1 whereas binary 0 is represented with absence of voltage. Figure 2 shows a method to simulate the process of sampling bits.

1

0 1 1

Figure 2:- Unipolar sampled signal

The encoded signal is then modulated onto a carrier signal using DSB-SC such that the amplitude of the carrier signal varies according to the message signal.  This is done by multiplying the sampled signal by a sinusoidal carrier signal of frequency !  (up-converter) as follows:

( ) = ( ) cos(2! )                                                         (1)

where ( ) is the resulting modulated signal and ( ) is the sampled signal.

The modulated  signal is transmitted over a wireless AWGN channel; i.e. the gain of the channel is  fixed (normalized gain equal to one). Therefore we only consider the effect of additive Gaussian noise.  The received

signal will be:

( ) = ( ) + ( )                                                                       (2)

where ( ) is a Gaussian random noise of power "22; i.e. ( )~ 40, "227.

At the receiver, the signal is demodulated by suppressing the carrier signal by multiplying the received signal by the local sinusoidal carrier signal (with the same carrier frequency), as shown in Eq. (3).

z(t) = x(t) cos(wc t)

= a(t) cos2 (wc t)

= a(t) + a(t) cos(2wc t)

(3)

Z(w) = F{z(t)}

= A(w) + [A(w - 2wc ) + A(w + 2wc )]

Subsequently, the demodulated signal is filtered (lowpass filter) to remove high frequency components (the 2! term). Finally, the received message is generated by considering the samples of each single bit.


Figure 3: demodulator

Due to the effect of the noise introduced by the channel, the signal sent to the demodulator is not x(t) buty(t). We could expect to receive some bits in error.  The robustness of the AM system can be measured by its Bit Error Rate (BER) performance, which is defined as

= (4)

Note that, BER performance is dependent on the Signal to Noise ratio (SNR). Suppose we have same signal transmit power, then higher SNR corresponds to lower noise power.

Matlab Work (35 marks)