# Matlab Programming Homework Help

The objective of the following Matlab programming homework help solution was to enable the students in developing a simulator for the switching of optical data. Information was provided on various aspects of the proposed simulator along with data contained in an excel spread sheet. Matlab was the software supposed to be used for simulation. Information was provided on description of components, dynamic performance, optical data. Matlab support code has been attached at the end along with the comments for the ease of reference. Solution also contains screenshots on simulator performance with sinusoidal input.
Report: Optical switching application

#### Optical Switching Simulation

In this work we simulate a fiber optic digital network switch based on the Mach-Zehnder interferometer. The device accepts single-mode electric field at an input port. Depending on the electric field applied to two Matlab Programming Assignment Help internal gates, the input field is routed to one of two output ports.

We visualize the signal at different nodes to understand the effects of individual components. We exploit the properties of complex sinusoids to efficiently model the effects of electronic components.

We find that the proposed design fails to exhibit ideal switching behavior. We propose simple changes that enhance the security and power consumption of the switch.

Description of the simulator

The simulator is implemented in MATLAB. The quantities of interest are electrical fields at various nodes along the system. Electric fields are help with Matlab programming homework represented by vectors of complex numbers. In particular, we limit ourselves to electric fields of the form

E(t;x)=〖E_0 exp〗⁡(2jπft)
where
〖Re(E(t;x) )=E_0 cos〗⁡2πft
Im(E(t;x) )=E_0 sin⁡2πft.

Optical devices are modeled as functions of the form

f:C^n→C^n.

That is, as functions defined over the n-dimensional vector field of complex numbers. Fibers are modeled as perfect wires with no attenuation nor dispersion. Hence, the concatenation of several optical Matlab programming homework help devices is simply a composition of functions.

%% Import data
clear;
[~, ~, raw] = xlsread('assignment.xls','assignment');
raw = raw(2:end,:);
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};

In particular, coupler modules are represented as functions with two inputs (for each input port) and two outputs (for each output port). The effect of the coupler upon an individual signal is to attenuate and delay. Each of these operations, in turn, is implemented by simple do my Matlab programming homework multiplication of the input field by an appropriate complex number. To attenuate a field E by a factor k and phase-delay it by an angle ϕ, we multiply it by the complex number k exp⁡(-jϕ). The resulting field from the attenuate-delay operation is:

E_AD (t)=k exp⁡(-jϕ)E(t)=k exp⁡(2πjft-ϕ).

Secondly, the charge-coupled electronic devices D_1and D_2 are implemented as a time-dependent phase delay. To obtain the output of the nth device, we multiply the input field by the quantity exp⁡〖(-j〗 ϕ(t)) to obtain the output field

E_(D_n )=exp⁡(-jϕ_n (t) )E(t)=exp⁡(2πjft-ϕ_n (t) ).

In our simulation, the nonlinear devices D_1 and D_2 have an electrical charge applied to them that modifies their Matlab Programming Assignment Help respective indices of refraction N_1 (t) and N_2 (t). Since the same charge is applied to both devices, we model

N_2 (t)=N_1 (t-Δl/c)

Where Δl is the physical separation between the devices and c is the speed of light. The quotient of the two quantities is chosen such that optical switching simulation  it represents approximately the duration of one data bit. Note that even Matlab programming project help though the index of refraction at each device is the same at time t, the signal traveling through the D_1 branch arrives Δl/c seconds earlier to D_1 than the signal traveling through the D_2 branch arrives at the corresponding device.

% Replace non-numeric cells with NaN
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
raw(R) = {NaN}; % Replace non-numeric cells
% Create output variable
data = reshape([raw{:}],size(raw));
% Allocate imported array to column variable names
t = data(:,1);      %s          - time
d = data(:,2);      %C/m^3      - charge density
% Correct NaN at t=0
t(1) = 0;
% Interpolate data
tt = linspace(0, t(end), length(t)*100);
d = interp1(t, d, tt)';
t = tt;
% Clear temporary variables
clearvars data raw R;
%% Prepare constants
% Constants
spb = 400;          %unitless   - samples per bit
c = 3e8;            %m/s        - speed of light
L = 500e-6;         %m
K = 2e-26;          %m^3
N0 = 3;             %unitless   - D1 and D2 initial index of refraction
C = 0.15;           %unitless
lambda = 1.5e-6;    %m          - Optical carrier wavelength
n = 1.0;            %unitless   - waveguide index of refraction
delta_l = 1;        %unitless
gamma = 0;          %unitless   - coupler insertion loss
A = [1 -1i; -1i 1]*sqrt(2)/2; %unitless   - coupler matrix
% Calculate phase change due to D1 and D2
dl_over_c = 100000;
N = N0-C*K*d;           %unitless   - time-varying ind. of refraction
N1 = [N; N(end)*ones(dl_over_c,1)]; %- ind. of refraction at D1
N2 = [N(1)*ones(dl_over_c,1); N];   %- ind. of refraction at D2
% Extend time axis
dt = t(2)-t(1);
t = t(1):dt:length(N1)*dt-dt;
phi1 = 2*pi*L*(N1-N1(1))/lambda; %rad - phase shift through D1
phi2 = 2*pi*L*(N2-N2(1))/lambda; %rad - phase shift through D2
%% Signal generator
f = c/lambda;
T = 2*pi/f;
nbits = floor(length(t)/spb);
b = randi(2,1,nbits)-1;
p = ones(1,spb);
% Convert bit sequence b to sample sequence d
d = zeros(size(phi1));
for n=0:nbits-1
d(1+n*spb:(n+1)*spb)= b(n+1)*p;
end
% Prepare transmission signal (choose one)
x = d'.*exp(2i*pi*f*t);     % Modulated bitstream
%x = exp(2i*pi*f*t/2300);    % Pure sinusoid
%% Execute simulation
E1_switch = x;              % Input E field at switch 1 (top branch)
E2_switch = E1_switch*0;    % Input E field at switch 2 (bottom branch)
% E fields after first coupler
[E3_intermediate, E4_intermediate] = coupler(E1_switch, E2_switch, gamma, A);
% E fields after D1 and D2
E1_intermediate = E3_intermediate.*exp(-1i*phi1)'; % top branch
E2_intermediate = E4_intermediate.*exp(-1i*phi2)'; % bottom branch
% E fields at output
[E3_switch, E4_switch] = coupler(E1_intermediate, E2_intermediate, gamma, A);

The phase shift ϕ_n (t) at each branch is given by

ϕ_n (t)=2πL(N_0-CK(δ(t) ) )/λ

where N_0 is a refractive index constant, C a factor that affects propagation, K the dependence of refractive index on the density of charge, L is the length of the device, λ the signal wavelength, and δ(t) the charge density in the device .

Note that when the input field can be expressed as a sum of complex exponentials these relationships still apply distributive Matlab programming homework help to each

%% Figure - phase shift at D1, D2 and effective phase shift
figure(1);
subplot(1,2,1)
plot(t,phi1,t,phi2);
grid on
xlabel('Time (s)');
legend('D1','D2','Location','NorthWest')
subplot(1,2,2)
grid on
plot(t,phi1-phi2);
xlabel('Time (s)');
%%

The given vector δN_n (t) has temporal resolution of 〖10〗^(-13) s. The carrier field has frequency f=2×〖10〗^14 Hz. In order to avoid aliasing, we interpolate the given vector to have a resolution of 5×〖10〗^(-16) s.

component; hence, as long as the input field can be represented by a sum of complex exponentials (i.e., its Fourier transform exists), our simulator remains reliable. The aforementioned components are sufficient to simulate the consequences of applying different input fields to the switching device.

Now, in order to benchmark the switch for use in a communication network, we implement a transmitter and Matlab programming help solution receiver using a simple modulation strategy, amplitude-shift keying.

% Figure - simulator performance with sinusoidal input
figure(2)
subplot(2,2,1)
plot(t, real(E1_switch), t, real(E2_switch))
title('Input E-fields')
xlabel('Time (s)')
ylabel('Normalized Real Amplitude')
legend('E1_{switch}', 'E2_{switch}', 'Location','northoutside','Orientation','horizontal')
subplot(2,2,2)
plot(t, real(E3_intermediate), t, real(E4_intermediate))
title('Coupler 1 Outputs')
xlabel('Time (s)')
ylabel('Normalized Real Amplitude')
legend('E3_{intermediate}', 'E4_{intermediate}', 'Location','northoutside','Orientation','horizontal')
subplot(2,2,3)
plot(t, real(E1_intermediate), t, real(E2_intermediate))
title('D1 and D2 Output')
xlabel('Time (s)')
ylabel('Normalized Real Amplitude')
legend('E1_{intermediate}', 'E2_{intermediate}', 'Location','southoutside','Orientation','horizontal')
subplot(2,2,4)
plot(t, real(E3_switch), t, real(E4_switch))
title('Coupler 2 Outputs')
xlabel('Time (s)')
ylabel('Normalized Intensity')
legend('E3_{switch}','E4_{switch}', 'Location','southoutside','Orientation','horizontal')

The transmitter first prepares a random bitstreamb. Then, b is expanded into a vector d consisting of each element of b repeated spb (samples-per-bit) times. d cannot be efficiently transmitted by the optical communications system because its main frequency is far away from the optimal (i.e., lowest-dispersion) frequencies of the system. The signal d is modulated by a carrier signal of Matlab programming homework help complex exponential form with frequency f=c/λ, where λ is the wavelength of the laser that has been designed for the system. Multiplication by this sinusoid centers the frequency components of the signal to the neighborhood around f (Proakis 2008). The resulting signal is used to modulate the laser, which generates the input electric field to the network.

At the receiver end, the output electric field is demodulated by multiplying it by the complex conjugate of the modulating sinusoid. Assuming no dispersion and no delay, the demodulation step recovers the help with Matlab programming homework input signal perfectly (Proakis 2008). Practical demodulators must deal with the consequences of signal paths with finite length and nonzero distortion, but for our purposes it suffices to assume a perfect modulator/demodulator.

%% Figure - Non-ideal switching performance at coupler 2 outputs
figure(3)
plot(t, abs(E3_switch), t, abs(E4_switch))
title('Coupler 2 Output Power')
xlabel('Time (s)')
ylabel('Normalized Power')
legend('E3_{switch}','E4_{switch}', 'Location','southoutside','Orientation','horizontal')
%% Figure - zero bit-error rate
figure(3);
% Trim E4_switch
E4_t = E4_switch(1:end-mod(length(E4_switch),10));
b_recovered = abs(intdump(real(E4_t.^2), spb))>0;
hold on;
stem(b)
stem(0.5*b_recovered)
fprintf('Bit error rate: %f\n', sum(b-b_recovered)/length(b));
legend('Transmitted', 'Recovered (scaled)')
xlabel('Index')
ylabel('Symbol')

To recover the bitstreambfrom the demodulated received signal, we use MATLAB’s built-in integrator function intdump() to add up everyspb samples. We declare any value above zero to represent a ‘1’ symbol and a ‘0’ symbol otherwise.

Results and discussion

The purpose of this simulation is to evaluate the feasibility of employing the proposed device as an optical switch. Hence, the question we seek to answer is, to what extent is the input signal present at each of the output ports in (a) steady state and (b) transient charge density in D_1 and D_2.

First, we analyze the effective phase shift introduced by D_1 and D_2. Figure (1) shows the phase shift (in radians) that a signal passing through Matlab programming homework help each of these devices undergoes. The effective phase shift Δϕ(t)=ϕ_1 (t)-ϕ_2 (t)defines the switching behavior. When it is flat, the input field appears at one of two outputs; during transient periods there will be electrical energy at both outputs.

Figure –phase shift  at , and effective phase shift

Figure (2) shows the effects of transmitting a pure sinusoid through our system. For illustrative purposes, the sinusoid shown has much lower frequency than the specified carrier with . From these plots we can understand the function of the switch. The input field E1switch has its energy evenly split by the Matlab programming homework help first coupler into two signals, E3intermediate and E4intermediate. Note that the latter is delayed by a quarter-wavelength. After passing through the electronic devices  and , the respective signals appear “stretched” in time in the transient charge period.  This is due to the time-varying phase delay introduced by the devices. After the device charge settles, the output signal has the Matlab Programming Assignment Help same wavelength as at the beginning. Finally, at the outputs of coupler 2 we observe the switching behavior. When , all of the input power goes to port 4 of coupler 2; when  most of the input power goes to port 3.

Figure –simulator performance with sinusoidal input

Note that the switch does not exhibit ideal behavior when diverting the input signal to port 3 of coupler 2. When input power is switched to output 3, output 4 continues to emit about 10% of the signal power. Figure (3) shows the power of the electric fields at each of these ports over time.

Figure – Non-ideal switching performance at coupler 2 outputs

Just how bad is this non-ideality? We consider the problem of reconstructing the input bitstream only through observing the output of port 4. In an ideal switch, it should be impossible to recover the help with Matlab programming assignment entire transmission (Gagliardi and Karp 1995). Figure (4) shows the transmission of a bitstream with  using the  carrier. Figure (5) shows the transmitted and recovered bitstreams from the experiment with a zero bit-error rate.

Figure – Transmission of a modulated bit stream through the switch

Figure – Zero bit-error rate achieved during switching

As Figure shows, the non-ideality of this switch is significant. As designed, the switch is (a) insecure, because it broadcasts the input signal to one of the output ports at all times and (b) inefficient, because it does not transmit all the input power to the desired output when port 3 is selected.

How feasible would it be to correct the design of the switch? As we have seen, the power at each port is a function of  When  or , all the input power is routed to one of the output ports. If the physical design of the devices  and  allowed it, ideal switching behavior could be achieved if their charge density were increased so that  exactly is achieved. Alternatively, if data Matlab programming project help security and not power consumption were the concern, a clamping device could be cascaded at port 4 of coupler 2 to attenuate the signal to zero intensity once it falls beneath a particular threshold (here, about 10% input power).

Conclusion

In this work we have evaluated an optical switch based on the Mach-Zehnder interferometer. In our development, we explain the construction of a simple MATLAB simulator for a single-mode switch operating at . Using a simple amplitude-shift keying modulator/demodulator, we show that the switch’s non-ideality allows the recovery of the input Matlab programming homework help bit stream from the “off” port. We suggest increasing the charge density of the devices  and  to achieve better switching when the intended output is port 3. If the physical design  of the switch renders such a change prohibitive, we suggest cascading a clamping device that attenuates the port 4 signal once it falls below 10% of nominal power to ensure data security.

Save

Save