⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isi_test.m

📁 64QAM matlab s programs.
💻 M
字号:
%---------------------------------------%
% Define Discrete Simulation Parameters %
%---------------------------------------%

num_pulses = 1000; % number of pulses to simulate
num_bits = num_pulses; % number of bits to transmit (binary)
num_samples_pulse = 99; % number of samples for pulse duration (note 4 bits/pulse)
bit_rate=100; % bits/s
bit_interval = 1/bit_rate; % length of time for each pulse
sample_rate = bit_rate*num_samples_pulse  % simulation samples/sec
sample_period = 1/sample_rate; % time for each simulation sample
total_time = num_pulses * bit_interval % total simulation time

% Set up time sample array for simulation
t = [0:sample_period:total_time-sample_period];

%----------------------%
% Generate binary data %
%----------------------%

% generate binary "message"
rand('seed',1)
bit_stream = rand(1,num_bits) > .5;

% make data polar
polar_data = double(bit_stream);
polar_data( find( bit_stream == 0 ) ) = -1;

% generate delta function data signal
start_sample_indices = [ (num_samples_pulse+1)/2 : num_samples_pulse : length(t) ];
delta_data = zeros(size(t));
delta_data(start_sample_indices) = polar_data;

% plot a small portion of the signal
plot(t,delta_data)
xlabel('t (seconds)');
ylabel('x_{in}(t) (Volts)')
title('Binary data converted to narrow polar pulses (almost Dirac deltas)');
axis([.3,.5,-2,2]);
grid

%-------------------------%
% Generate pulse waveform %
%-------------------------%

A=1; % Amplitude of the pulse
rect = A*ones(1,num_samples_pulse);

% Try using raised cosine pulses and compare outputs
% after passing through channel. 
% Raised cosine output should have esentially zero ISI, provided with
% sufficient bandwidth.  Hint: See my powerpoint presentation on ISI for 
% the definition of a raised cosein pulse.  Use alpha = .5 and let 
% T = bit_interval.  

% generate raised cosine
% Eq. 7.35, p. 315
t2=[-4*bit_interval:sample_period:4*bit_interval];
alpha=.5;
rcos=sinc(bit_rate*t2).*(  (cos(alpha*pi*bit_rate*t2)./(1-4*(alpha*bit_rate*t2).^2))  );

% Let raised cosine have the same energy as rect
rcos = rcos * sum(rect.^2) / sum( rcos.^2 )

BW = (1+alpha)*(bit_rate/2) % raisedd cosine bandwidth

% Plot rect and raised cosine pulses (same energy)
figure
plot(t2,t2>-bit_interval/2 & t2 < bit_interval/2,'b-',t2,rcos,'r-')
xlabel('t (sec)')
ylabel('p(t)');
legend('Rectangular','Raised Cosine')
title('Pulse Shapes (Same Energy)')


%---------------------%
% Perform line coding %
%---------------------%

% Rectangular pulse 
x_rect = conv2(delta_data,rect,'same');


% Raised cosine pulse
x_rcos = conv2(delta_data,rcos,'same');


figure
plot(t,x_rect,'b-',t(start_sample_indices),x_rect(start_sample_indices),'ro')
xlabel('t (seconds)');
ylabel('x(t) (Volts)')
title('Polar NRZ PCM (Rectangular Pulses)');
axis([.3,.5,-2,2])
grid

figure
plot(t,x_rcos,'b-',t(start_sample_indices),x_rcos(start_sample_indices),'ro')
xlabel('t (seconds)');
ylabel('x(t) (Volts)')
title('Polar NRZ PCM (Raised Cosine Pulses)');
axis([.3,.5,-2,2])
grid

% Look at PSD of rect and rcos signals
% Show PSD
figure
subplot(211)
periodogram( x_rect, [], 1024, round(sample_rate) );
title('PSD Rectangular Pulses');

subplot(212)
periodogram( x_rcos, [], 1024, round(sample_rate) );
title('PSD Raised Cosine Pulses');

% Raised cosine pulse signal is much more spectrall compact!


%------------------%
% Simulate Channel %
%------------------%

%%% Low pass filter %%%
fir_length = 1201;
channel_bandwidth = BW
% bit_rate/2 = minimum for NRZ, 
% (sample_rate)/2 = full bandwidth possible with discrete simulation
equiv_discrete_bandwidth = 2 * pi * channel_bandwidth * sample_period % rads/sample
n = -( fir_length-1 ) / 2 : ( fir_length-1 ) / 2;
warning off MATLAB:divideByZero
h = sin( equiv_discrete_bandwidth * n ) ./ ( pi * n );
h( (fir_length+1)/2 ) = equiv_discrete_bandwidth / pi;
h = h / sum(h);

% Perform convolution (using 'same' option to avoid delay for simplicity)
% Output will be same size as input and will not have any delay
% In a real system some delay will be present, but it does not affect the
% performance.
y_rect = conv2(x_rect,h,'same');  % The models the channel "blurring" (LPF) 
y_rcos = conv2(x_rcos,h,'same');  % The models the channel "blurring" (LPF) 


% % Add noise
% noise_std = 10;
% randn('state',1);
% noise = randn(size(y_rect))*noise_std;
% y_rect = y_rect + noise;
% y_rcos = y_rcos + noise;
% 
% 
% % Matched Filter
% y_rect = conv2(y_rect,rect/sum(rect(:)),'same');
% y_rcos = conv2(y_rcos,rcos/sum(rcos(:)),'same');


figure
plot(t,y_rect,'b-',t(start_sample_indices),y_rect(start_sample_indices),'ro')
xlabel('t (seconds)');
ylabel('y(t) (Volts)')
title(sprintf('Polar PCM (Rectangular) After Channel (Channel %2.2fHz)',...
    round(channel_bandwidth)));
axis([.3,.5,-2,2])
grid


figure
plot(t,y_rcos,'b-',t(start_sample_indices),y_rcos(start_sample_indices),'ro')
xlabel('t (seconds)');
ylabel('y(t) (Volts)')
title(sprintf('Polar PCM (Raised Cos) After Channel (Channel %2.2fHz)',...
    round(channel_bandwidth)));
axis([.3,.5,-2,2])
grid

%------------------%
% Make Eye Pattern %
%------------------%

y_eye_data_rect = reshape( y_rect, num_samples_pulse, num_bits );
figure
plot(y_eye_data_rect)
title('Eye Pattern (Rectangular)')
grid
axis([0,100,-1.5,1.5])
% Height smaller, great prob of error

y_eye_data_rcos = reshape( y_rcos, num_samples_pulse, num_bits );
figure
plot(y_eye_data_rcos)
title('Eye Pattern (Raised Cosine)')
grid
axis([0,100,-1.5,1.5])
% Width smaller, harder on timing

%------------%
% Demodulate %
%------------%

% demodulate
out_bits_rcos = y_rcos(start_sample_indices) > 0;
out_bits_rect = y_rect(start_sample_indices) > 0;

% compute probability of error
pe_rcos = bit_error_probability( bit_stream, out_bits_rcos )
pe_rect = bit_error_probability( bit_stream, out_bits_rect )


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -