A Software Defined Radio Implementation Using MATLAB Ziyi Feng Information Technology
by user
Comments
Transcript
A Software Defined Radio Implementation Using MATLAB Ziyi Feng Information Technology
Ziyi Feng A Software Defined Radio Implementation Using MATLAB Information Technology 2013 FOREWARD This project started in the January, 2013 and was completed in April, 2013. The goal of this project is to design a radio communication system in audio band using audio devices such as a sound card. The functions have been realized successfully. I want to give my whole sincere and grateful appreciations to Principal Lecturer, Dr. Chao Gao. As my supervisor of the thesis work, he tried his best to help me. Without his help and guidance I cannot bring the theories into practice. Whenever I met problems he came up with the solutions as soon as possible. Mr Gao is the most patient teacher I have ever seen. I cannot thank him more. On the other hand, I want to thank all my friends for their always supports spiritual, fortunately we can share the last time in bachelor stage together. 1 VAASAN AMMATTIKORKEAKOULU UNIVERSITY OF APPLIED SCIENCES Degree program in Information Technology ABSTRACT Author Ziyi Feng Title A Software Defined Radio Implementation Using MATLAB Year 2013 Language English Pages 47 Name of Supervisor Chao Gao Software Defined Radio (SDR) is a hot topic of wireless communication research in recent years. The idea of SDR is to use ultra-high speed sampling and ADC/DAC modules directly measure the received radio signal and decode whatever it contains. The aim of this project is to study and understand SDR using MATLAB in audio frequency band. In this project, both analog and digital modulation and demodulation methods are studied. Two Matlab sessions are set for sender and receiver respectively in Windows 7. A simulation of signal modulation and demodulation can be presented clearly just with Matlab. 2 TABLE OF CONTENTS FOREWARD ....................................................................................................... 1 ABSTRACT ........................................................................................................ 2 LIST OF ABBREVIATIONS ............................................................................... 4 LIST OF FIGURES ............................................................................................. 5 LIST OF LISTINGS ............................................................................................ 7 1. INTRODUCTION ........................................................................................... 8 2. TECHNOLOGY BACKGROUND .................................................................. 9 2.1 Basic Concepts of Modulation and Demodulation ...................................... 9 2.2 Analog Modulation and Demodulation ....................................................... 9 2.2.1 AM Modulation and Demodulation .................................................. 10 2.2.2 FM Modulation and Demodulation .................................................. 12 2.3 Digital Modulation and Demodulation...................................................... 13 2.3.1 BPSK Modulation and Demodulation .............................................. 13 2.3.2 QPSK Modulation and Demodulation .............................................. 16 2.3.3 FSK Modulation and Demodulation................................................. 19 3. MATLAB IMPLEMENTATION .................................................................... 21 3.1 General Structure of System ..................................................................... 21 3.2 Modulator Implementation ....................................................................... 23 3.3 Demodulator Implementation ................................................................... 26 4. RESULTS AND ANALYSIS .......................................................................... 33 5. SUMMARY AND CONCLUSIONS .............................................................. 45 REFERENCES .................................................................................................. 46 3 LIST OF ABBREVIATIONS AM Amplitude Modulation BFSK Binary Frequency Phase-Shift Keying BPSK Binary Phase-Shift Keying FM Frequency Modulation FWR Full Wave Rectifier LPF Low Pass Filter PM Phase Modulation QPSK Quadrature Phase-Shift Keying SDR Software Defined Radio 4 LIST OF FIGURES Figure 1Voltage define in AM .......................................................................... 10 Figure 2 Block diagram of coherent AM receiver ............................................. 11 Figure 3 Block diagram of non-coherent AM receiver ...................................... 12 Figure 4 Block diagram of BPSK transmitter ................................................... 14 Figure 5 Block diagram of BPSK receiver ....................................................... 14 Figure 6 Process of carrier recovery ................................................................. 15 Figure 7 Constellation map of QPSK ............................................................... 17 Figure 8 Block diagram of QPSK transmitter ................................................... 18 Figure 9 Block diagram of QPSK receiver ....................................................... 18 Figure 10 Block diagram of FSK transmitter.................................................... 19 Figure 11 Block diagram of FSK non-coherent receiver ................................... 20 Figure 12 Block diagram of radio communication system ................................ 21 Figure 13 Model of radio communication system............................................. 22 Figure 14 Block diagram of a normal communication system .......................... 22 Figure 15 Transmitter ...................................................................................... 33 Figure 16 Receiver .......................................................................................... 34 Figure 17 Original signal ................................................................................. 34 Figure 18 AM signal (modulated signal) .......................................................... 35 Figure 19 Received AM signal ......................................................................... 35 Figure 20 Received signal after FWR .............................................................. 35 Figure 21 Demodulated signal ......................................................................... 36 Figure 22 Carrier signal and modulated FM signal ........................................... 37 Figure 23 Received FM signal ......................................................................... 37 Figure 24 Demodulated signal ......................................................................... 38 Figure 25 Original signal ................................................................................. 38 Figure 26 Part of modulated BPSK signal ........................................................ 39 5 Figure 27 Part of received BPSK signal ........................................................... 39 Figure 28 Truncated BPSK signal .................................................................... 39 Figure 29 Recovered carrier ............................................................................. 40 Figure 30 Demodulated signal ......................................................................... 40 Figure 31 Original signal ................................................................................. 41 Figure 32 Part of the received QPSK signal ..................................................... 41 Figure 33 Received QPSK signal ..................................................................... 41 Figure 34 Demodulated signal ......................................................................... 42 Figure 35 Original information ........................................................................ 42 Figure 36 Part of BFSK signal ......................................................................... 43 Figure 37 Received BFSK signal ..................................................................... 43 Figure 38 Signal after envelop detection .......................................................... 43 Figure 39 Demodulated signal ......................................................................... 44 6 LIST OF LISTINGS Listing 1 AM modulation ................................................................................. 23 Listing 2 FM modulation ................................................................................. 23 Listing 3 BPSK modulation ............................................................................. 24 Listing 4 QPSK modulation ............................................................................. 25 Listing 5 BFSK modulation ............................................................................. 26 Listing 6 AM demodulation ............................................................................. 27 Listing 7 FM demodulation.............................................................................. 27 Listing 8 BPSK demodulation ......................................................................... 29 Listing 9 QPSK demodulation ......................................................................... 31 Listing 10 BFSK demodulation........................................................................ 32 7 1. INTRODUCTION Traditional radio communication systems need a lot of hardware components such as demodulator, detector, filter, etc. which makes the platform cost very high for undergraduate level study and research. But the Laboratory exercises and studies on that aspect are necessary for related teachers and students. Software Defined Radio (SDR) makes it possible to implement the radio communication process simply with software. Comparing to the traditional radio communication systems, SDR omits all the hardware and replaces them by pure software. This solution also gives a great advantage in flexibility because a SDR receiver is able to decode all the signals. However, the devices like A/D convertor, powerful signal processor still cost too much for undergraduate level studies, some modifications have been done to adjust the SDR to be suitable for students to use; it‟s what this project does. The frequencies used in this communication system are limited into audio band, and so it can be handled by a normal sound card. Thus the system can be constructed with simple facilities. With this system students even can study radio communication system at home only with a computer installed Matlab. The project will employ one desktop PC with MATLAB installed and simulates the radio communication process. Two Matlab sessions are executed at the same time, one as transmitter, and the other as receiver. When the project works, the signal is produced in transmitter and transmitted as sound after modulated. Then the receiver will receive the signal by recording it. The information can be obtained after demodulation. There are five modulation methods studied in this project. The modulation and demodulation processes are designed according to the related theory. The rest of this thesis is arranged as follows. Chapter 2 describes the technology background which contains basic ideas about signal modulation and demodulation ,also the five different methods are introduced; Chapter 3 explains how the system implemented on Matlab; Chapter 4 presents the project results and analysis; finally Chapter 5 concludes the work. 8 2. TECHNOLOGY BACKGROUND 2.1 Basic Concepts of Modulation and Demodulation In radio communication system the signal with high frequency has been transmitted. On one hand, only the signal with high frequency can be transmitted over a long distance; on the other hand, the height of antenna has a strong relationship with the signal frequency. The lower the frequency is the higher the antenna is. Thus to transmit low frequency signal may require a very high antenna which even cannot be made out. Whenever the signal with low frequency needs to be transmitted it is necessary and important to modulate it to a high frequency signal. Only in this way can the signal be transmitted in the radio communication system/1/. The signal used to carry message is called carrier signal; typically it is a high-frequency sinusoid or cosine waveform. The carrier signal can be transmitted via the air over a long distance. The process of making the radio frequency carrier signal carry the information signal with low frequency is modulation. Modulation can be realized by varying one or more features of a carrier signal/2/. When the receiver receives modulated signal, it has to process the modulated carrier signal and get the original information; this process is demodulation. Its function is opposite to that of modulation. 2.2 Analog Modulation and Demodulation As said above modulation is the process of varying one or more features of a carrier signal. If the modulating signal is analog and the variation for the parameters of carrier signal based on the modulating signal is continuous, the modulation is treated as analog modulation. The parameters can be changed in carrier signal are amplitude and angle, while the angle contains frequency 𝜔 and phaseθ. When the amplitude of carrier signal varies as the modulating signal, it is amplitude modulation (AM); if the other two parameters are changed, it is called frequency modulation (FM) and phase modulation (PM) respectively/2/. AM and FM are focused in this project. 9 2.2.1 AM Modulation and Demodulation In amplitude modulation, the carrier signal‟s amplitude Vc varies in proportion to the instantaneous amplitude of the modulating signal voltage 𝑒𝑚 /3/. Amplitude modulation is a linear modulation process because of superposition principle/2/. Figure 1 shows the defined voltage in amplitude modulation. Figure 1Voltage define in AM The modulation index is an important parameter that describes the degree of modulation. It affects the shape of the AM signal and expressed as m= 𝑽𝒎 𝑽𝒄 (Vm, Vc have been shown in the Figure 1). If the modulation index is more than 1, the carrier signal will turn off when Vm equals the lowest amplitude. Thus m should not be more than 1, namely m<=1, in other words Vm ≤ Vc . Envelop of AM signal is an imaginary line drawn along the peak value of each wave cycle. It can be expressed as 𝑒𝐸𝑁𝑉 =𝑉𝑐 + 𝑒𝑚 . As 𝑒𝑚 = 𝑉𝑚 ∗ 𝑠𝑖𝑛 𝜔𝑚 𝑡, the envelop of AM becomes 𝑒𝐸𝑁𝑉 =𝑉𝑐 + 𝑉𝑚 ∗ 𝑠𝑖𝑛 𝜔𝑚 𝑡 (1) 10 As m= 𝑉𝑚 𝑉𝑐 the Equation (1) can be changed to 𝑒𝐸𝑁𝑉 =𝑉𝑐 (1 + 𝑚 ∗ 𝑠𝑖𝑛 𝜔𝑚 𝑡) (2) The instantaneous voltage of AM signal 𝑒𝐴𝑀 should be the multiplication of the envelop and the carrier signal, thus it can be expressed as 𝑒𝐴𝑀 = 𝑒𝐸𝑁𝑉 ∗ 𝑠𝑖𝑛 𝜔𝑐 𝑡, namely, 𝑒𝐴𝑀 = 𝑉𝑐 (1 + 𝑚 ∗ 𝑠𝑖𝑛 𝜔𝑚 𝑡) ∗ 𝑠𝑖𝑛 𝜔𝑐 𝑡 (3) eAM is the AM signal that has already get the information inside and used to be transmitted to the receiver. For the demodulation part, it is an opposite process of modulation. There are two different methods to fulfill the demodulation, coherent and non-coherent. The coherent demodulation can be used when the receiver knows the phase of the received signal. The general coherent demodulation process is shown in Figure 2. Figure 2 Block diagram of coherent AM receiver As the Figure 2 shows, the received AM signal has to be multiplied by the carrier signal produced by the local oscillator in receiver. The key procedure is that the receiver must produce a carrier signal which has same phase and frequency with the received signal‟s carrier signal. The other method is non-coherent demodulation; it‟s used in this project. In non-coherent method, the carrier signal is not necessary but the envelop line is used. The demodulation process is shown in Figure 3. 11 Figure 3 Block diagram of non-coherent AM receiver Full wave rectifier converts the whole signal to DC. To be exactly it makes all the inputs to be positive or negative. The low pass filter can be designed to let the signals with expected frequency pass. 2.2.2 FM Modulation and Demodulation Comparing to AM, FM has different properties. In FM modulation, the amplitude of carrier remains constantly; while the frequency varies based on the modulating signal. More specifically, the frequency deviation between carrier signal‟s original frequency and its instantaneous frequency after modulating is in proportion to the instantaneous amplitude of the modulating signal (input signal) /3/. There is also a concept of modulation index in FM modulation, but it‟s completely different from the AM‟s. In FM, the modulation index indicates how much the modulated signal‟s frequency varies from the carrier signal‟s frequency. It is defined as the ratio of maximum frequency deviation and the modulating signal‟s frequency /4/ /5/. The formula is 𝑚= ∆𝑓 (4) 𝑓𝑚 Suppose the modulating signal is a cosine wave fm (t) and the carrier signal is also a sine wave fc(t)=Acsin(2πfct), then the modulated signal should be y(t)=Ac sin(2𝜋 𝑡 0 𝑓 𝜏 𝑑𝜏) (5) ∆f f(τ) is instantaneous frequency which should be (fc+ A *fm(t)), then we can m transfer the Equation (5) to be y(t)=Ac sin(2𝜋 𝑡 (𝑓𝑐 0 =Ac sin (2𝜋fct+2𝜋 ∆f + A ∗ 𝑓𝑚 𝜏 )𝑑𝜏) m (6) ∆f 𝑡 𝑓 (𝜏)𝑑𝜏) Am 0 𝑚 12 For fm(𝜏)=Amcos(2πfm𝜏), 𝑡 𝑓 (𝜏)𝑑𝜏= 0 𝑚 𝑠𝑖𝑛 (2𝜋 𝑓𝑚 𝑡) Am 2𝜋 𝑓𝑚 y(t)= Acsin(2𝜋fct+2𝜋 ∆f Am , then we can obtain ∗ 𝐴𝑚 𝑠𝑖𝑛 (2𝜋𝑓𝑚 𝑡) 2𝜋 𝑓𝑚 ∆𝑓 = Acsin(2𝜋fct+𝑓 ∗ 𝑠𝑖𝑛 (2𝜋𝑓𝑚 𝑡)) 𝑚 In which ∆𝑓 𝑓𝑚 ) (7) = m and y(t) is the modulated signal. Equation (7) shows the basic theory of frequency modulation in mathematics. For the demodulation part, similar with AM, FM also can be demodulated by coherent and non-coherent methods. The coherent method is suitable for narrow band FM signal and the receiver must know the phase shift of the received signal. Thus the coherent method is only applied in a limit area. While the non-coherent method has no this kind of limitation; it can be applied to both narrow band FM and wide band FM. In this project, the FM signal is demodulated by the function in Matlab. It‟s not so accurate but useful. 2.3 Digital Modulation and Demodulation The modulation process is digital modulation when the modulating signal is digital. Compared with analog modulation, digital modulation has a lot of advantages, for example greater noise immunity, greater security, etc. /6/. Similar with analog modulation, there are three features can be modulated on carrier by the digital information. Thus three major kinds of digital modulation technologies are used in radio communication system. They are Amplitude-Shift Keying (ASK), Frequency-Shift Keying (FSK) and Phase-Shift Keying (PSK). In this project, one kind of FSK and two kinds of PSK are studied. 2.3.1 BPSK Modulation and Demodulation BPSK stands for Binary Phase-Shift Keying which is the simplest PSK. In BPSK the carrier signal‟s phase varies between two values according to the modulating signal. BPSK is also called 2-PSK for the two values has 180°difference. The 13 method to modulate carrier is when the signal is bit „1‟, the carrier‟s phase is one value; while when the bit is „0‟, carrier‟s phase changes to another value. The pair of phase 0 and π is used in this project. Suppose carrier signal is y1=cos(2*pi*fc*t), phase of this carrier is 0,from mathematic knowledge, it can be known that y2= cos(2*pi*fc*t+pi)= -cos(2*pi*fc*t)= -y1 (8) Equation (8) offers the method to modulate the signal. When signal is bit „1‟, BPSK signal is y1, otherwise it‟s –y1. The process of modulation is shown in Figure 4. Figure 4 Block diagram of BPSK transmitter For the demodulation part, there are both coherent and non-coherent methods. The coherent one is used in the project. The process of demodulation is shown in Figure 5. Figure 5 Block diagram of BPSK receiver In theoretical, received BPSK signal should be r(t)=Acos(2 πfct+ kπ) (k=0,1) (9) 14 In this situation the carrier signal used to demodulate received signal can be as the same as the transmitter‟s; process of carrier recovery can be omitted. But in reality, received signal‟s phase is not only 0 or pi; it may have a phase shift φ. In this situation, received BPSK signal is r(t)=Acos(2 πfct+ kπ+𝜑) (k=0,1) (10) The demodulation result will be wrong if receiver still use the same carrier recovery signal. To handle this problem carrier recovery circuit is used, which means to get the carrier signal from the received signal itself. The process of carrier recovery is described by Figure 6. Figure 6 Process of carrier recovery Carrier can be recovered from r(t) based on the following mathematic analysis y=r2(t)=cos2(2 πfct+ kπ+ φ) (k=0,1) (11) 1 𝑦 = 𝐴2 (1 + cos (2 𝜋 ∗ 2𝑓𝑐 ∗ 𝑡 + 2𝑘𝜋 + 2𝜑) 2 1 =2 𝐴2 (1 + cos (2 𝜋 ∗ 2𝑓𝑐 ∗ 𝑡 + 2𝜑) (12) Let the signal y passes the high pass filter, the signal becomes 1 y’=2 𝐴2 cos (2 𝜋 ∗ 2𝑓𝑐 ∗ 𝑡 + 2𝜑) (13) At last, divide this signal‟s frequency to be half through a low pass filter, the carrier signal can be recovered to 1 y’’=2 𝐴2 cos (2 𝜋 ∗ 𝑓𝑐 ∗ 𝑡 + 2𝜑) (14) Compare Equation (14) with Equation (10), we can find there is a phase difference, this may lead to bad demodulation result. To get the right carrier signa, y‟‟ has to be shift a phase of 𝜑. Finally the correct carrier is obtained 15 1 carrier=2 𝐴2 cos (2 𝜋 ∗ 𝑓𝑐 ∗ 𝑡 + 𝜑) (15) Receiver can multiply the received signal with this carrier signal to demodulate it. The other method to overcome the phase shift problem is to use preamble. Preamble means a certain sequence always transmitted before the real information. With preamble, it can be known exactly when the signal starts. Receiver will know the signal it should receive, in other words, receiver knows the phase it should receive. Thus whenever signal has been received, receiver can cut the signal from the expected phase. For example, if the preamble is 1 1, then the signal‟s phase should be 0, when we receive signal like Equation (10), we can cut it to be a signal expressed by Equation (9). This can be done by cutting the received signal from one peak value (for cosine wave). To demodulate this signal, just use the same carrier signal with transmitter is enough. In this situation, the carrier signal can be produced by the receiver local oscillator. Comparing these two methods, the second one is simpler. The first one is used in this project to demodulate the BPSK signal but there is a little modification. 2.3.2 QPSK Modulation and Demodulation Quadrature Phase-shift keying is another phase-shift modulation method which is a little more complex than BPSK. It has twice the bandwidth efficiency of BPSK, since two bits are transmitted in a single modulation symbol /6/.Two bits lead to four different patterns „00‟,‟01‟,‟10‟ and „11‟. Thus the carrier signal‟s phase varies among four values; each value stands for one pattern. The name Quadrature comes from the feature of the four phases that the difference between two adjacent pattern‟s phases is 90°. There are two kinds of phase combinations which are usually used in modulation; one is 0,π/2, π and 3π/2, the other one is π/4,3π/4,5π/4 and 7π/4. 16 Figure 7 Constellation map of QPSK The phase relationship can be seen clearly from Figure 7. The triangles show the first phase combination, while the circles show the second phase combination. The second phase combination is used in this project for the circuits and hardware of producing these phases is easier to be realized in the real systems. The information signal is transmitted bit by bit. As said before two bits form one signal symbol, the bits stream should be separated to two sequences by breaking two bits in one symbol before modulating carrier. Then for each sequence, the modulation process is similar with BPSK (see Figure3). But the two carrier signals for the two branches have two different phases. To make the modulated signal QPSK has four phases of π/4,3π/4,5π/4 and 7π/4,one branch‟s carrier signal should has the phase 0, while the other one has the phase π/2. The two branches‟ outputs are added together to form the modulated QPSK signal. Figure 8 shows the process of QPSK modulation. 17 Figure 8 Block diagram of QPSK transmitter For QPSK demodulation part, it also has coherent and non-coherent methods; we use the coherent one. General process of QPSK coherent demodulation with preamble is shown in Figure 9. Figure 9 Block diagram of QPSK receiver The „ctI‟ and „ctQ‟ in Figure 9 means the two different carrier signals mentioned before. They are same with the carrier signals used in the corresponding transmitter. In QPSK demodulation the problem of phase shift also exists and it can be handled also by both carrier recovery and preamble; the basic theories have been explained before. Preamble is used here and the sequence is „1111‟, so the received signal should start at phase pi/4. When receiver receives QPSK signal it truncates the signal from certain position. Then the truncated signal can be demodulated with the carrier signals generated by local oscillator. 18 2.3.3 FSK Modulation and Demodulation Frequency-shift keying modulation is simpler than PSK. Binary FSK is the simplest one in FSK modulation. In BFSK a pair of frequency is used to present the signal bits „1‟ and „0‟. The carrier‟s frequency varies between two values according to the signal state-binary 1 or 0/5/. The frequency for binary 1 is „mark‟ frequency while the other frequency for binary 0 is „space‟ frequency/7/.It also can be seen as two carrier signals have same amplitude and phase but different frequency and each carrier signal presents one signal state. There are a lot of methods to make BFSK modulation, one of them is making use of the feature that BFSK signal can be seen as formed by two carriers. For each carrier, the amplitude of carrier varies according to the signal bits. Thus for each branch it can be treated as Amplitude-shift keying (ASK). FSK signal can be seen as sum of two ASK signals. ASK is easy to be produced by multiplying the information signal with carrier signal directly. Figure 10 shows the process of producing FSK signal with ASK theory. Figure 10 Block diagram of FSK transmitter Through Figure 10 we can see when signal bit is „1‟ carrier 1 will be kept and carrier 2 will become to 0 after passing multiplier, then the FSK signal will be carrier 1, otherwise FSK will be carrier 2. Thus FSK signal‟s frequency varies based on signal bits. For FSK demodulation part, the non-coherent method is used. Figure 11 shows the process of non-coherent demodulation 19 Figure 11 Block diagram of FSK non-coherent receiver BFSK signal can be demodulated easily with this process. From Figure 11 we can see firstly let received signal pass two different band pass filters to get the corresponding signal. And then through the envelop detector the two branches‟ information has been obtained. Lastly after making judgment and comparing two branches‟ outputs the information is demodulated out. 20 3. MATLAB IMPLEMENTATION 3.1 General Structure of System A realistic SDR implementation should have some equipment, such as high speed A/D convertor, powerful signal processor. That equipment makes the platform too expensive for us students to study radio communication. To solve this problem Matlab is used in this project and the radio signal‟s frequency is limited in audio band. When set up transmitter and receiver two Matlab sessions are used; one works as transmitter and the other as receiver. All the modulation and demodulation works are completed with Matlab programming. When use this system the user just needs to choose the modulation and demodulation method and corresponding parameters. There are two ways to transmit the signal; one is over the air to simulate radio communication, and the other is using a cable. The first one is major studied. Figure 12 shows the basic structure of this radio communication system. Figure 12 Block diagram of radio communication system 21 Figure 13 Model of radio communication system Figure12 and Figure 13 show the radio communication system exactly. It can be seen that just one laptop installed Matlab 2011Rb is enough to study the process of radio communication. Transmitting signal with cable has also been tested. It uses the same transmitter and receiver, but the signal is transmitted by the cable. Figure 14 Block diagram of a normal communication system Figure14 shows the basic structure of a normal communication system simulated by the Matlab. One extra sound card is needed to offer “line in” and “line out” interfaces. One cable is also needed to transmit signal. This system works very well but the soundcard may affect the signal a little. For example, it may cause a 22 lot of attenuation that leads to the result that a different modulated signal is received by receiver. 3.2 Modulator Implementation This modulator is designed to modulate five kinds of signal, AM, FM, BPSK, QPSK and BFSK. Listing 1 will explain the detailsy about AM modulation. %%%%This part is AM modulation; the first two lines define the carrier signal and modulating signal. The carrier frequency fc and modulation index m can be set dynamically. %%%%%% carrier = 0.5*sin(2*pi*fc*t); signal = sin(2*pi*fm*t); am = (1+m*signal).*carrier; % AM signal is generated based on the Equation (3) sound(am, FS); %This function is used to make the signal to be sound, the signal is transmitted with this method. Listing 1 AM modulation For FM part, it‟s similar with AM, but the equation used to generate FM signal is different. %%%%This part is FM modulation; the modulating signal is put in the modulation equation directly and frequency is fm. The carrier frequency fc and modulation index mf can be set dynamically. %%%%%% carrier = VC*sin(2*pi*fc*t); % FM signal is generated based on the Equation (7). FM = VC*sin(2*pi*fc*t+mf*sin(2*pi*fm*t)); sound(FM, FS); %Transmit signal Listing 2 FM modulation Digital signal is a little more complex than analog signal. A sequence should be generated firstly as the original modulating signal. For BPSK, it is simply formed according to the block diagram shown in Figure 4. 23 %%%%This part is BPSK modulation; the carrier frequency fc can be set dynamically. %%%%%% carrier=0.2*cos(2*pi*fc*t); %carrier signal bk=[1 1 1 1 0 1 0 1 1 0 0 1]; bk2=[bk,bk]; % signal bits are preset %% double the signal to transmit two times of signal once bkt= kron (bk2,ones(1,fs)); % transfer the sequence into time domain bktp= 2*bkt-1; %modify the signal from unipolar to bipolar which means bit ‘0’ becomes to ‘-1’. bpsk=bktp.* carrier; % BPSK modulation based on Figure 4 sound(bpsk,fs); Listing 3 BPSK modulation In this modulation process, the original unipolar signal is changed to bipolar signal. After multiply with carrier signal, when original bit is 1 the modulated signal is same with carrier and the phase is 0; when original bit is 0 the modulated signal will be –carrier. According to Equation (8) it is the original carrier signal with 180 degree‟s phase shift in fact. Thus in modulated signal phase 0 presents signal bit 1 and phase π presents signal bit 0. For QPSK the basic modulation theory is similar but has some extra steps. This modulator is designed according to Figure 8. %%%%This part is QPSK modulation; the carrier frequency fc can be set dynamically. %%%%%% ctI = A0*cos(2*pi*fc*t); ctQ = A0*cos(2*pi*fc*t + pi/2); %% two carriers with two different phases %1. Generate random binary stream bk and double it for the purpose of transmitting twice signal once. bk = [1 1 1 1 0 0 0 1 0 1 ]; bk=[bk,bk]; 24 %2. Separate bk into bkI and bkQ, then transfer them into time domain respectively bkI = bk(1:2:N); bkQ = bk(2:2:N); BKI = 2*(kron(bkI, ones(1,fs)))-1; BKQ = 2*(kron(bkQ, ones(1,fs)))-1; % 3. Multiply bkI with ctI, and bkQ with ctQ; modulate two branches according to the similar theory with BPSK branch1 = ctI.*BKI; branch2 = ctQ.*BKQ; % 4. Add the multiplication results together, it is QPSK qpsk = branch1 + branch2; %5.transmitte the original signal 2 times sound(qpsk,fs); Listing 4 QPSK modulation At last, the BFSK signal can also be produced in this modulator. The process of producing BFSK signal is totally different from PSK; it is designed based on Figure 10. %%%%This part is FSK modulation; the two carriers’ frequency f1 and f2 can be set dynamically. %% %%%There are two carrier signals with same amplitude and phase but different frequency; each presents one signal state carrier1=cos(2*pi*f1*t); carrier2=cos(2*pi*f2*t); 1. Generate random binary stream bk and transfer them into time domain bk=[1 1 1 1 0 1 0 1 1 1 0 0]; 25 bkt= kron (bk,ones(1,FS)); 2. Generate two ASK signals. Signal bit 1 is presented by carrier 1’s frequency, while signal bit 0 will be presented by the other carrier’s frequency. ASK1=bkt.*carrier1; ASK2= (-bkt+1).*carrier2; 3. Add two ASK signals together to get FSK signal fsk =ASK1+ASK2; Listing 5 BFSK modulation 3.3 Demodulator Implementation Corresponding to transmitter, the receiver can also demodulate the five kinds of modulated signals. Receiver is also designed that user can choose the demodulation method and the corresponding parameters. Firstly, it‟s AM signal. The AM signal is demodulated by the non-coherent method. According to Figure 3 a full wave rectifier and a low pass filter should be designed. %% This part is AM demodulation part. It uses non-coherent method. %%%%% recAM = audiorecorder (FS,16,1,1); % construct a recorder object recordblocking(recAM,T); % start to record the signal for T seconds AM=getaudiodata(recAM); %%get the signal data from the record object %% The following command designs the full wave rectifier. When AM signal is positive, (AM>=0) will return 1 and (AM<0) returns 0, then the positive signal itself will be left. When AM signal is negative, (AM<0) will return 1, then the signal (-AM) will be left. Signal’s negative part is converted to be positive. In this way, the whole signal has been positive. The required full wave rectifier’s function has been realized. %% fwr = AM.*(AM>=0) + (-AM).*(AM<0); %% This command designs a low pass filter. The first parameter defines the order of the filter and the second parameter defines the frequency with which the signal can pass the filter. % 26 B = fir1(501, 0.001); %%This is the last step; to filter the FWR output with the filter designed before.% demod = filter(B, 1, fwr); Listing 6 AM demodulation From Listing 6, we can see it is easy to handle the signal with the programming. The signal is received by recording the sound, and then let the received signal pass the full wave rectifier. At last after through the filter the original signal is obtained. For FM signal, the corresponding demodulation function in Matlab is used to demodulate it. %%This is the FM signal demodulation part; it uses the demodulation function to demodulate it. %%% % 1. Receive FM signal by recording and then get the recording data. recFM = audiorecorder (FS,16,1,1); recordblocking(recFM,T); FM=getaudiodata(recFM); % 2. Call the function ‘fmdemod()’ to demodulate the signal signal= fmdemod(FM,fc,FS,mf*fm); %3.design the required low pass filter. After the signal through the filter the original signal can be demodulated out. B = fir1(401, 2*fm/FS); signal2 = filter (B,1,signal); Listing 7 FM demodulation Besides the above two analog demodulation methods, three digital demodulation methods are also necessary. In digital part, both coherent and non-coherent methods have been studied; more details are in the following part. 27 Firstly, it‟s BPSK demodulation part. The coherent method is used to demodulate the BPSK signal. %% This is the demodulation part for BPSK signal; the carrier recovery has been done in this part. % recBPSK = audiorecorder (FS,16,1,1); recordblocking(recBPSK,T); BPSK=getaudiodata(recBPSK); % 1. Truncate the signal from phase 0. % find the average peak strength, then get the right peak value BPSK2=FZY_smooth(BPSK); [xr,locr]=findpeaks(BPSK2); meanp = mean(xr); [row,colmn]=find(xr>(meanp)); %cut the signal from the peak value, namely from the cosine wave’s 0 phase BPSK2=BPSK2(locr(row(1)):end); %2.recover the carrier from truncated signal BPSK2 B = fir1(822,1.83*fc/(FS/2),'high'); A=BPSK2.*BPSK2; hpout=filter(B,1,A); %high pass filter design %make second power of the truncated signal % let the power result pass high pass filter % get the signal still from phase 0 to eliminate the high pass filter delay. [x loc] = findpeaks(hpout); ls=loc(50); hpout2=hpout(ls:end); %%divide the frequency to be the half; carrier signal’s frequency should be fc, but the frequency of ‘hpout’ is 2fc. fdout=interp(hpout2,2); carrier=fdout(1:length(fdout)/2); 28 %3. Demodulate the truncated BPSK signal with the recovered carrier BL= fir1(4001,2.5e-4); %low pass filter design %multiply received signal with recovered carrier signal y=BPSK2(1:length(carrier)).*carrier; signal=filter(BL,1,y); %pass the low pass filter Listing 8 BPSK demodulation BPSK signal is demodulated based on the process described in Figure5, but the carrier recovery part is a little different from the description in Figure 6. Firstly, the received signal BPSK has been truncated from phase 0 to be a new signal BPSK2. The equation is BPSK2 (t) =Acos(2 πfct+ kπ) (k=0) However, for a signal r(t)=Acos(2πfct+ kπ) (k=0,1),no matter the value of k is 1 or 0 the carrier can be recovered from it according to the analysis in 2.3.1.and there is no problem ofφ . Thus the carrier signal can be recovered from the BPSK2 without phase shift. The received signal can also be truncated from phase π ,and carrier signal still can be recovered by the same process. Then for QPSK signal, preamble is used to demodulate the received signal. The sequence „1 1 1 1‟ is sent before other information signal bits. According to the analysis in technology background part we can know that receiver should receive the signal from phaseπ /4. Listing 9 is the demodulation part of QPSK signal. %% This is the demodulation part for QPSK signal. Preamble is used to complete that. The process of demodulation is described in Figure 9. % recQPSK = audiorecorder (FS,16,1,1); recordblocking(recQPSK,T); QPSK=getaudiodata(recQPSK); %1.cut the received signal from the expected phase. % Find the received signal’s peak value and then make sure how many data should be cut to get phase 0%% 29 QPSK2=FZY_smooth(QPSK); [xr,locr]=findpeaks(QPSK2); meanp = mean(xr); [row,colmn]=find(xr>(meanp)); % the expected phase should be pi/4 for the bits 1 1 should be received. From the expected phase to make sure how many data should be cut. %%%% phasetime=pi/4/(2*pi)*(1/fc); shift1=ceil(phasetime*FS); ls1=locr(row(10)); % firstly cut the signal from the 0 phase to get signal QPSK2 and then cut it to get truncated signal which starts from the expected phase. QPSK2=QPSK2(ls1:end); ls2=ls1+shift1; QPSK3=QPSK2(shift1:end);%%%cut the signal from the pi/4 phase %2.define the two carriers same with transmitter ctI = cos(2*pi*fc*t3); ctQ = cos(2*pi*fc*t3 + pi/2); %3.demodulate the signal based on Figure 9 % multiply two carriers with the received signal respectively. aip=QPSK3'.*ctI(1:length(QPSK3)); aqp=QPSK3'.*ctQ(1:length(QPSK3)); %design the low pass filter BL=fir1(15000,5e-5); % let the signal pass the low pass filter aIPP=filter(BL,1,aip); aQPP=filter(BL,1,aqp); %4. Judge the signal, the accurate original signal can be obtained after 30 judgment. aIPPP=aIPP>0; aQPPP=aQPP>0; Listing 9 QPSK demodulation The demodulation of QPSK is realized by the codes in Listing 9. We can see the process of carrier recovery can be omitted with the help of preamble. The results are also very good. We will see that in Chapter 4. Lastly, it comes to BFSK signal. The non-coherent method is used to demodulate the received BFSK signal. %% BFSK demodulation part%%%%% recFSK = audiorecorder (FS,16,1,1); recordblocking(recFSK,T); FSK=getaudiodata(recFSK); %1.through band pass filter%%%%%%%%% %firstly, two different band pass filters are designed according to the expected frequency values.BP1 is used to get signal represented by frequency f1.BP2 is for frequency f2.%%%% parang=[0.9,1.1]; Wn1=f1*parang/(FS/2); BP1=fir1(101,Wn1,'bandpass'); Wn2=f2*parang/(FS/2); BP2=fir1(101,Wn2,'bandpass'); %secondly, let received signal FSK passes the two band pass filters respectively. x1=filter(BP1,1,FSK); x2=filter(BP2,1,FSK); %2. Envelop detection %%%%%%%%%%% 31 % Mathematically the envelope e(t) of a signal x(t) is defined as the magnitude of the analytic signal (complex signal)/8/. Firstly modify the signal from real to complex with the function of Hilbert (). y1=hilbert(x1); y2=hilbert(x2); % based on the mathematic theory described before the absolute values of the complex signal can be obtained with the function abs (). Envelop of received signal is detected in this way. envy1=abs(y1); envy2=abs(y2); %3.Sample&judge%%%%%%%%%% % get the original signal from the two envelop signals c1= (min (envy1) +max (envy1))/2; c2= (min (envy2) +max (envy2))/2; FSK1=envy1>c1; FSK2=envy2>c2; FSKOUT=FSK1>FSK2; Listing 10 BFSK demodulation The demodulation of BFSK signal has been done based on the process of Figure 11. We can see the filters and other required functions can be completed well with the software. 32 4. RESULTS AND ANALYSIS Two windows will appear when the system works; one is transmitter, and the other is receiver. They are designed by Matlab guide. Figure 15 and Figure 16 show the two GUIs. In the two GUIs, modulation methods and other corresponding parameters can be set. These parameters must be same in both two GUIs, or the result will be wrong. Figure 15 Transmitter Figure15 shows an example of choosing amplitude modulation. The carrier frequency and modulation index should be chose from the available values. The notice shows other information for this modulation. In receiver the method of amplitude modulation and the same parameters should be set. 33 Figure 16 Receiver The following part will show the modulation and demodulation results for all the five modulation methods. Firstly, it‟s AM signal. Figure 17, 18, 19, 20 and 21 show the situation of 1 kHz, modulation index is 0.5. Figure 17 Original signal 34 Figure 18 AM signal (modulated signal) Figure 19 Received AM signal Figure 20 Received signal after FWR 35 Figure 21 Demodulated signal Figure 17 shows the signal needs to be transmitted. Figure 18 shows the modulated signal. After transmitting via the air the received AM signal is shown in Figure 19. The AM signal‟s shape still can be recognized, but it has a little attenuation. The amplitude has been decreased a lot. This is because of the sound card channel attenuation. Figure 20 shows the signal after FWR. It can be seen clearly that the entire signal has been positively, which verifies that the FWR works. At last Figure 21 shows the demodulated signal. Comparing to Figure 17, we can see the original signal is almost recovered from the received AM signal, but there is a litter attenuation and delay. The attenuation is caused by both the channel (air) and the filter; however, the delay is caused by the filter. Secondly, it‟s FM signal. The frequency 1500 Hz and the modulation index 4 are used to be an example. In Figure 22, the first diagram shows the carrier signal. It can be figured out that the signal‟s frequency is 1500 Hz. Then the second diagram shows the modulated FM signal. It‟s obviously that the frequency varies as time and the variation is regularly. Figure 23 shows the received FM signal. The signal‟s frequency varies like the FM signal in transmitter dose, but the amplitude changes. This is not correct in normal situation, but it has no effect on demodulation process for the demodulation only relies on the frequency variations. 36 Figure 22 Carrier signal and modulated FM signal Figure 23 Received FM signal 37 However, it‟s still better to eliminate the amplitude variation in Figure 23, but it‟s difficult in this system. Many methods have been tried to handle this problem, for example adjust the value of frequency or the modulation index. Those methods don‟t work. It has also been tried to lower the amplitude of the transmitted FM signal for we guess maybe the sound card in laptop cannot handle that signal strength. But it still fails. At last, we find that maybe it‟s because the attributes of the laptop‟s speaker and microphone. There are other filters or amplifiers in those two equipments which may change the signal a lot. If another better sound card is installed in the laptop the results can be improved. Figure 24 Demodulated signal Figure 24 shows the demodulated signal; the frequency is the expected one. The FM modulation and demodulation work well in this system. Thirdly, the BPSK signal is tested. Carrier signal‟s frequency is 1500 Hz. Figure 25 Original signal 38 Figure 26 Part of modulated BPSK signal Figure 27 Part of received BPSK signal Figure 28 Truncated BPSK signal Figure 25 shows that the signal bit changes from 1 to 0 at fourth seconds. Then in Figure 26 we can see the phase of the signal varies to pi to represent the bit 0. The frequency of the signal is 1500 Hz as said before. Figure 27 shows the received BPSK signal, although there are a lot of distortions it still can be seen that the signal‟s phase has changed to pi suddenly like transmitted BPSK signal. The variation causes amplitude fluctuations; however, it goes to nearly normal level after a while. 39 As said in chapter three, the received BPSK signal is truncated to eliminate the extra phaseφ . Figure 28 shows the truncating result in which the signal starts from phase 0. For this received signal the carrier doesn‟t need to make a phase change. Figure 29 Recovered carrier Figure 30 Demodulated signal The carrier has been recovered successfully which is shown in Figure 29. The value of the key parameter phase is 0 which is what we expect. The fact that the recovered carrier signal‟s amplitude lower than the received BPSK signal‟s is caused by the process of carrier recovery. The procedure of making power of BPSK signal make the signal‟s amplitude decrease much. Figure 30 shows the demodulate result. Comparing to Figure 25 the original signal has been demodulated out successfully from received signal. However, 40 there are less signal bits than the original one because receiver starts later than transmitter. Receiver hasn‟t received the first several bits. Fourthly, it‟s QPSK signal. The carrier frequency is 1000 Hz in this example. Figure 31 Original signal Figure 32 Part of the received QPSK signal Figure 33 Received QPSK signal 41 Similar with BPSK, the phase is also the key component in QPSK. In Figure 32 it can be seen that the value of phase varies to 5pi/4 to represents binary bit “0 0” which is what we expect in technology background part. Figure 34 Demodulated signal Figure 34 shows the demodulated result. It is almost same with the original information shown in Figure 31. The preamble works very well but there are also some delay which makes the demodulated signal has fewer signals than original signal. Lastly, it comes to BFSK signal; two carriers are needed to do that. The two frequencies 3500Hz and 1000Hz are used to make the demonstration. Figure 35 Original information 42 Figure 36 Part of BFSK signal Figure 37 Received BFSK signal Figure 38 Signal after envelop detection 43 Figure 39 Demodulated signal Figure 36 shows that when signal bit changes from 1 to 0 the frequency of the signal varies to a lower value. The frequency variation is obviously. Figure 37 shows the received BFSK signal. It has a big difference with transmitted BFSK signal. The value of amplitude varies as the frequency; signal with lower frequency has lower amplitude. Similar with FM modulation method this phenomenon has little effect on demodulation but it shouldn‟t appear in normal system. This also should be caused by the inner filters or amplifiers in laptop speaker and microphone. Figure39 shows that the BFSK demodulated result. The original signal bits have been obtained except the first several bits. 44 5. SUMMARY AND CONCLUSIONS The system has been completed well. According to the results in fourth chapter the system works well. In this system five modulation methods in totally have been studied, two analog modulation methods and three digital ones. From this project it can be known that phase modulation method is more difficult than frequency modulation method for the receiver has to know the phase it should receive. While in receiver the non-coherent demodulation method is usually used for it doesn‟t care what the suitable carrier signal is. And the non-coherent demodulation is also easier to be implemented with the circuits. Through the construction process of this system, the modulation methods can be studied more than the class in which only the theory part is known. What‟s more, the equipment is simple and easy. To do this practice only one laptop installed with Matlab is enough. Thus this system is suitable for students to study radio communication by themselves. It is also can be a lab for students to enhance the understanding of concept of modulation and demodulation. This system is deserved to be studied. Another benefit from this project is practicing the ability of signal processing. When programming in Matlab, a lot signal processing method is needed, for example to design a suitable filter. The filter designed in this system is not good enough and can be improved. For further study in this system, other modulation methods can be added in this system and then they can be studied. Besides the modulation methods many other aspects can be improved. For example to add preamble in transmitter signal and then the receiver can be modified to check the preamble first. If the preamble is right it keeps on receiving the signal or it can reject the transmitting. A checksum also can be added in receiver to check if the signal is right. 45 REFERENCES /1/ U.A.Bakshi, A.P.Godse 2009. Basic Electronics Engineering. Technical Publications. Chapter 8.5. /2/ Kundu Sudakshina 2010. Analog and Digital Communications. Pearson Education India. pp. 163–184. ISBN 978-81-317-3187-1. /3/ Warren Hioki 2001, Telecommunications 4/e, Prentice Hall, /4/ About FM modulation. Accessed April 10,2013 http://en.wikipedia.org/wiki/Frequency_modulation /5/ About FM modulation. Accessed April 10,2013 http://www.cdt21.com/resources/Modulation/modulation_FM.asp /6/ Theodore S. Rappaport, Theodore Rappaport, 2002 Wireless Communications: Principles and Practice (2nd Edition). Prentice Hall PTR, ISBN: 0130422320 /7/ FSK definition. Accessed April 16,2013 http://en.wikipedia.org/wiki/Frequency-shift_keying /8/ Envelop detection. Accessed April 21,2013 http://www.mathworks.se/help/dsp/examples/envelope-detection.html 46