Вы находитесь на странице: 1из 3

Codul sursa pentru simularea modulatiei PSK in Matlab:

%% Phase Shift Keying Simulation % This demo shows how to simulate a basic Quarternary Phase Shift Keying (QPSK % communication lin! that will allow you to generate empirical performance % cur"es that can be compared to those from theoretical predictions# % %% $nitiali%ing "ariables % The first step is to initiali%e "ariables for data rate& carrier fre'uency& % sampling rates& number of symbols to simulate& alphabet si%e (M & signal to % noise ratios (S()& S()*bit # The last line seeds the random number % generators# +d , -. +c , /. +s , 01. ( , +s*+d. numSymb , -22. M , /. S()p3it , -/. S() , S()p3it*log1(M . seed , 4-10/5 5/01-6. rand(7state7& seed(- . randn(7state7& seed(1 . %% 8enerating random information symbols % (e9t& use ):(;S)C to generate random information symbols from 2 to M<-# Since % the simulation is of QPSK& the symbols are 2 through 0# The first -2 data % points are plotted abo"e# numPlot , -2. rand(7state7& seed(- . msg=orig , randsrc(numSymb&-&42:M<-6 . stem(42:numPlot<-6& msg=orig(-:numPlot &7b97 . 9label(7Time7 . ylabel(7:mplitude7 . %% Phase modulating the data on a carrier % >se ;M?; to phase modulate the data on a carrier with fre'uency / times the % data rate and to upsample to a sampling rate @ times the carrier fre'uency# % (ote in the plot that the phase changes at the symbol boundaries# grayencod , bit9or(42:M<-6&floor(42:M<-6*1 . msg=gr=orig , grayencod(msg=origA- . msg=t9 , dmod(msg=gr=orig& +c& +d& +s& 7ps!7& M . numModPlot , numPlot B +s. t , 42:numModPlot<-6#*+s. plot(t& msg=t9(-:length(t &7b<7 . a9is(4 min(t ma9(t <-#5 -#56 . 9label(7Time7 . ylabel(7:mplitude7 .

%% Creating the noisy signal % Then use :C8( to add noise to the transmitted signal to create the noisy % signal at the recei"er# >se the 7measured7 option to add noise that is -/ d3 % below the a"erage signal power (S() , -/ d3 # The term& <-2Blog-2(( & is used % to scale the noise power with the o"ersampling# The term& <-2Blog-2(2#5 & is % used to reduce the noise power to match the bandpass signal representation# % Plot the recei"ed signal# randn(7state7& seed(1 . msg=r9 , awgn(msg=t9& S()<-2Blog-2(2#5 <-2Blog-2(( & 7measured7& 46& 7d37 . plot(t& msg=r9(-:length(t &7b<7 . a9is(4 min(t ma9(t <-#5 -#56 . 9label(7Time7 . ylabel(7:mplitude7 . %% )eco"ering information from the transmitted signal % Then use ;;DM?; to demodulate the signal& detect the symbol that was % transmitted& and downsample to the original information rate# The detected % symbols are plotted in red stems with circles and the transmitted symbols are % plotted in blue stems with 97s# The blue stems of the transmitted signal are % shadowed by the red stems of the recei"ed signal# Therefore& comparing the % blue 97s with the red circles indicates that the recei"ed signal is identical % to the transmitted signal# msg=gr=demod , ddemod(msg=r9& +c& +d& +s& 7ps!7& M . 4dummy graydecod6 , sort(grayencod . graydecod , graydecod < -. msg=demod , graydecod(msg=gr=demodA- 7. stem(42:numPlot<-6& msg=orig(-:numPlot &7b97 . hold on. stem(42:numPlot<-6& msg=demod(-:numPlot &7ro7 . hold off. a9is(4 2 numPlot <2#1 0#16 . 9label(7Time7 . ylabel(7:mplitude7 . %% Comparing original message to demodulated message % +inally& use 3$TD)) and SEMD)) to compare the original message to the % demodulated message# 3$TD)) is used to determine the bit error rate and % SEMD)) is used to determine the symbol error rate# 4error3it ratio3it6 , biterr(msg=orig& msg=demod& log1(M . 4errorSym ratioSym6 , symerr(msg=orig& msg=demod .

%% )unning simulation e9amples % The ne9t two steps e9ecute e9amples files& S$MP:SS3:(;DF and S$M3:SD3:(;DF& % which are complete passband and baseband simulation e9amples for Quaternary % PSK (QPSK & respecti"ely# They demonstrate how to create simulation dri"ers % in M:TG:3 that plot the simulation results as they are generated# %% )unning the passband QPSK simulation e9ample % The green and magenta lines are the theoretical bit error rate (3D) and % symbol error rate (SD) performance cur"es for QPSK& respecti"ely# The % e9ample& S$MP:SS3:(;DF& plots the simulated 3D) and SD) in red and blue lines& % respecti"ely# S$MP:SS3:(;DF uses ;M?; and ;;DM?; to simulate QPSK at % passband# simpassbande9(42:-:56 %% )unning the baseband QPSK simulation e9ample % The green and magenta lines are the theoretical bit error rate (3D) and % symbol error rate (SD) performance cur"es for QPSK& respecti"ely# The % e9ample& S$M3:SD3:(;DF& plots the simulated 3D) and SD) in red and blue lines& % respecti"ely# S$M3:SD3:(;DF uses ;M?;CD and ;;DM?;CD to simulate PSK at % baseband using a comple9 en"elope representation of the modulated signal# % >sing ;M?;CD and ;;DM?;CD instead of ;M?; and ;;DM?; allows you to % simulate communication lin!s using a lower sampling rate& reducing the simulation % time# simbasebande9(42:-:56 .

Вам также может понравиться