0% found this document useful (0 votes)
17 views7 pages

Octave Programming

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

Octave Programming

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Octave Programming

By
Mary Roshia Peter
963321106060
Abstract:

• This document provides an introduction to computing using


Octave. It will teach you how to use Octave to perform
calculations, plot graphs, and write simple programs.
• The close compatibility of the open-source Octave package with
MATLAB (by The Mathworks) , which is heavily used in industry and
academia, gives the user the opportunity to learn the syntax and
power of both packages where funding and licence restrictions
prevent the use of commercial packages.
• To maintain the ideal of learning both Octave and Matlab from
this tutorial, the differences between Octave and Matlab have
been highlighted and details of any modifications etc. required to
run a function/program with Matlab are noted.
Introduction
GNU Octave is a scientific programming language for scientific
computing and numerical computation. Octave helps in
solving linear and nonlinear problems numerically, and for
performing other numerical experiments using a language
that is mostly compatible with MATLAB. It may also be used as
a batch-oriented language.
Basic syntax of octave
Octave uses a comma or space to separate entries in a row, and a
semicolon or carriage return to separate one row from the next. Ending
a command with a semicolon tells Octave not to print the result of the
command. For example, octave:2> B = rand (3, 2);
Program:
QAM_MIMO_BER.m% Script for computing the Bit Error Rate (BER) for Binary Phase Shift Keying (BPSK) modulation in a% Rayleigh fading
channel with 2 Transmitters (Tx) and 2 Receivers (Rx) MIMO channel,% using Minimum Mean Square Error (MMSE) equalization.clear; % Clear
workspace variablesN = 10^6; % Number of bits or symbolsEb_N0_dB = [0:21]; % Multiple Eb/N0 values in dBnTx = 2; % Number of
transmittersnRx = 2; % Number of receiversfor ii = 1:length(Eb_N0_dB) % Transmitter % Generate random bit sequence for transmission ip =
rand(1, N) > 0.5; % Generating 0s and 1s with equal probability s = 1 * ip - 1; % BPSK modulation: 0 -> -1; 1 -> 0 % Modulate the symbols for
MIMO transmission sMod = kron(s, ones(nRx, 1)); sMod = reshape(sMod, [nRx, nTx, N / nTx]); % Generate Rayleigh fading channel h =
1/sqrt(2) * [randn(nRx, nTx, N / nTx) + j * randn(nRx, nTx, N / nTx)]; % Generate white Gaussian noise with 0dB variance n = 1/sqrt(2) *
[randn(nRx, N / nTx) + j * randn(nRx, N / nTx)]; % Channel and noise addition y = squeeze(sum(h .* sMod, 10)) + 10^(-Eb_N0_dB(ii) / 20) * n;
% Receiver % Compute the MMSE equalization matrix: W = inv(H^H*H + sigma^2*I)*H^H hCof = zeros(2, 2, N / nTx); hCof(1, 1, :) = sum(h(:,
2, :) .* conj(h(:, 2, :)), 1) + 10^(-Eb_N0_dB(ii) / 10); hCof(2, 2, :) = sum(h(:, 1, :) .* conj(h(:, 1, :)), 1) + 10^(-Eb_N0_dB(ii) / 10); hCof(2, 1, :) = -
sum(h(:, 2, :) .* conj(h(:, 1, :)), 1); hCof(1, 2, :) = -sum(h(:, 1, :) .* conj(h(:, 2, :)), 1); hDen = ((hCof(1, 1, :) .* hCof(2, 2, :)) - (hCof(1, 2, :) .*
hCof(2, 1, :))); hDen = reshape(kron(reshape(hDen, 1, N / nTx), ones(2, 2)), 2, 2, N / nTx); hInv = hCof ./ hDen; hMod = reshape(conj(h), nRx,
N); yMod = kron(y, ones(1, 2)); yMod = sum(hMod .* yMod, 1); yMod = kron(reshape(yMod, 2, N / nTx), ones(1, 2)); yHat =
sum(reshape(hInv, 2, N) .* yMod, 1); % Receiver - hard decision decoding ipHat = real(yHat) > 0; % Counting the errors nErr(ii) =
size(find([ip - ipHat]), 2);end% Compute simulated BERsimBer = nErr / N;% Compute theoretical BER for nRx=1 and nRx=2EbN0Lin = 10 .^
(Eb_N0_dB / 10);theoryBer_nRx1 = 0.5 * (1 - (1 + 1 ./ EbN0Lin) .^ (-0.5));p = 1 / 2 - 1 / 2 * (1 + 1 ./ EbN0Lin) .^ (-1 / 2);theoryBerMRC_nRx2 = p .^
2 .* (1 + 2 * (1 - p));% Plot BER curvesclose all;figure;semilogy(Eb_N0_dB, theoryBer_nRx1, 'bp-', 'LineWidth', 2);hold on;semilogy(Eb_N0_dB,
theoryBerMRC_nRx2, 'kd-', 'LineWidth', 2);semilogy(Eb_N0_dB, simBer, 'mo-', 'LineWidth', 2);axis([0 25 10^-5 0.5]);grid on;legend('Theory
(nTx=2, nRx=2, ZF)', 'Theory (nTx=1, nRx=2, MRC)', 'Simulation (nTx=2, nRx=2, MMSE)');xlabel('Average Eb/No (dB)');ylabel('Bit Error
Rate');title('BER for BPSK modulation with 2x2 MIMO and MMSE equalizer (Rayleigh
channel)');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Assignment Questions:% 1. Explore Multiple Eb/N0 ranges% 2. Explore the impact of QPSK, 16-QAM on BER in MIMO% 3. Explore how
Noise immunity differs with different modulation
schemes%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
Output:

You might also like