www.gusucode.com > MATLAB仿真技术与应用__的配套例题和习题的matlab源代码 > 第五章/example8.m

    %MATLAB program 5-8
%8-QASK
%clear all;
%clc;
% Number of symbols in alphabet
M = 8;
% Number of symbols in the original message
len = 10000; 
% Assume the original message is sampled
Fd = 1; 
% at a rate of 1 sample per second.
Fs = 3; % The modulated signal will be sampled
% at a rate of 3 samples per second.
% Create a signal.
signal = randint(len,1,M); % Random digital message
% consisting of integers between 0 and M-1
% Use M-ary QASK modulation with two different labeled
% square constellations.
modsignal(:,1) = dmodce(signal,Fd,Fs,'qask',M);
inphase = [-3:2:3, -3:2:3];
quad = [ones(1,4), -1*ones(1,4)];
modsignal(:,2) = dmodce(signal,Fd,Fs,'qask/arb',inphase,quad);
% Add noise to real and imaginary parts of the modulated signal.
noisy = modsignal+.5*randn(len*Fs/Fd,2)...
   +j*.5*randn(len*Fs/Fd,2);
% Demodulate to recover the message.
newsignal(:,1) = ddemodce(noisy(:,1),Fd,Fs,'qask',M);
newsignal(:,2) = ddemodce(noisy(:,2),Fd,Fs,...
   'qask/arb',inphase,quad);
% Check whether Gray code resulted in fewer bit errors.
% Compare signal with each column of newsignal.
[num,rate] = biterr(newsignal,signal); 
disp('Bit error rates for the two constellations used here')
disp('--------------------------------------------------------')
disp(['Gray code constellation:     ', num2str(rate(1))])
disp(['Non-Gray code constellation: ', num2str(rate(2))])
% Plot signal constellations with Gray code labeling.
modmap('qask',M);