SS Matlab Theory
SS Matlab Theory
t = -5:0.01:5;
u = t >= 0;
% Impulse Function
delta = t == 0;
% Ramp Function
r = t .* (t >= 0);
figure;
subplot(3,1,1);
xlabel('Time (t)');
ylabel('u(t)');
grid on;
subplot(3,1,2);
title('Impulse Function');
xlabel('Time (t)');
ylabel('\delta(t)');
grid on;
subplot(3,1,3);
title('Ramp Function');
xlabel('Time (t)');
ylabel('r(t)');
grid on;
t = -5:0.01:5;
alpha = 0.5;
% Rectangular Signal
% Triangular Signal
% Signum Function
signum = @(t) sign(t);
f = 1; % Frequency in Hz
figure;
subplot(3,3,1);
xlabel('Time (t)');
ylabel('exp(\alpha t)');
grid on;
subplot(3,3,2);
xlabel('Time (t)');
ylabel('Re\{exp(j\omega t)\}');
grid on;
subplot(3,3,3);
ylabel('Im\{exp(j\omega t)\}');
grid on;
% Rectangular Signal
subplot(3,3,4);
title('Rectangular Signal');
xlabel('Time (t)');
ylabel('rect(t)');
grid on;
% Triangular Signal
subplot(3,3,5);
title('Triangular Signal');
xlabel('Time (t)');
ylabel('tri(t)');
grid on;
% Signum Function
subplot(3,3,6);
title('Signum Function');
xlabel('Time (t)');
ylabel('sign(t)');
grid on;
% Sine Function
subplot(3,3,7);
plot(t, sine_signal, 'LineWidth', 2);
title('Sine Function');
xlabel('Time (t)');
ylabel('sin(2\pi ft)');
grid on;
% Cosine Function
subplot(3,3,8);
title('Cosine Function');
xlabel('Time (t)');
ylabel('cos(2\pi ft)');
grid on;
n = -50:50;
alpha = 0.1;
f = 0.05; % Frequency in Hz
figure;
subplot(3,3,1);
ylabel('exp(\alpha n)');
grid on;
subplot(3,3,2);
ylabel('Re\{exp(j\omega n)\}');
grid on;
subplot(3,3,3);
ylabel('Im\{exp(j\omega n)\}');
grid on;
subplot(3,3,4);
ylabel('rect[n]');
grid on;
subplot(3,3,5);
ylabel('tri[n]');
grid on;
subplot(3,3,6);
ylabel('sign[n]');
grid on;
ylabel('sin(2\pi fn)');
grid on;
subplot(3,3,8);
ylabel('cos(2\pi fn)');
grid on;
4. INTRODUCTION TO SIMULINK:
1. Graphical Interface:
- Simulink provides a block diagram interface where users can drag and drop blocks
representing various components of a system. These blocks can be connected to define
the flow of signals and data between them.
3. Modeling:
- Simulink supports modeling systems that span multiple domains, such as mechanical,
electrical, hydraulic, and thermal systems, allowing for the integration of different physical
components into a single simulation environment.
- Simulink provides powerful simulation capabilities, enabling users to run their models
and observe the behavior of the system over time. Results can be visualized using scopes,
plots, and other visualization tools.
6. Code Generation:
- Simulink offers automatic code generation tools that can convert models into C, C++, or
HDL code. This feature is particularly useful for implementing control algorithms on
embedded systems and hardware platforms.
7. Model-Based Design:
1. Creating a Model:
- Start by opening Simulink from the MATLAB interface and creating a new model. Add
blocks to the model from the library browser and connect them to define the system.
2. Configuring Parameters:
- Set parameters for each block according to the system requirements. Parameters can
include gains, initial conditions, sample times, etc.
3. Running Simulations:
- Configure the simulation settings, such as start and stop times, solver options, and step
sizes. Run the simulation to see how the system behaves over time.
4. Analyzing Results:
- Use scopes and other visualization blocks to observe the outputs of the system. Analyze
the results to ensure the system meets the desired performance criteria.
- Modify the model as needed based on the simulation results. This iterative process
helps in refining the design and improving system performance.
- Use the code generation tools to convert the model into executable code for
deployment on hardware platforms.
2. From the Simulink Library Browser, add the following blocks to the model:
- Connect the output of the Step block to the input of the Transfer Function block.
- Connect the output of the Transfer Function block to the input of the Scope block.
- Set the numerator to `[1]` and the denominator to `[1 1]`, representing a first-order
system with a time constant of 1.
- Set the Step time to `1`, Initial value to `0`, and Final value to `1`.
- Double-click the Scope block to view the output response of the system.
This simple example demonstrates how to create and simulate a basic dynamic system in
Simulink. As you become more familiar with Simulink, you can explore its advanced
features and build more complex models.
Simulink's intuitive interface and powerful simulation capabilities make it a valuable tool
for engineers and researchers working on a wide range of applications, from control
systems and signal processing to mechanical and electrical system design.
Analyzing basic signals using Simulink involves creating models that generate, process,
and visualize these signals. Here's a step-by-step guide on how to analyze basic signals,
including sine, cosine, step, impulse, and ramp functions, using Simulink.
1. Open MATLAB.
2. In the MATLAB command window, type `simulink` and press Enter to open the Simulink
library browser.
1. In the Simulink start page, click on "Blank Model" to create a new model.
To generate the basic signals, we need to add source blocks from the Simulink library.
1. **Sine Wave**:
- In the Simulink Library Browser, navigate to `Sources`.
- Drag and drop the **Sine Wave** block into the model.
2. **Cosine Wave**:
- Simulink doesn't have a direct Cosine Wave block, but you can use a Sine Wave block
and adjust the phase.
- Drag and drop another **Sine Wave** block into the model.
- Double-click the block and set the Phase (rad) parameter to `pi/2` to generate a cosine
wave.
3. **Step Function**:
- Navigate to `Sources`.
4. **Impulse Function**:
- Navigate to `Sources`.
- Drag and drop the **Pulse Generator** block into the model.
- Set the Pulse type to "Sample based", set the Amplitude to `1`, Period to a large value
(e.g., `1000`), and Pulse width to a very small value (e.g., `1`).
5. **Ramp Function**:
- Navigate to `Sources`.
3. Create multiple Scope blocks for each signal or use a **Mux** block to combine signals
into one Scope.
2. If using a Mux block, connect the outputs of the signal source blocks to the inputs of the
Mux block, and connect the output of the Mux block to the Scope block.
- Double-click the Sine Wave blocks and set the parameters such as Amplitude,
Frequency (rad/sec), and Phase (for cosine).
2. **Step**:
- Double-click the Step block and set the Step time, Initial value, and Final value.
3. **Impulse**:
4. **Ramp**:
- Double-click the Ramp block and set the Slope and Start time.
Here's how the Simulink model setup might look in text form:
- **Sinks**: Scope.
- Step to Scope.
- Set Amplitude = 1, Frequency = 2*pi (for 1 Hz), Phase = pi/2 (90 degrees).
Step Function
Impulse Function
Ramp Function
1. Add the Ramp block.
By following these steps, you can create and analyze various basic signals in Simulink,
allowing for a visual understanding of their behaviors and properties.
t = -2*pi:0.01:2*pi;
figure;
% Plot the first signal (sine wave)
subplot(3,1,1);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(3,1,2);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(3,1,3);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
n = -10:10;
%% Impulse Signal (Unit Impulse)
impulse_signal = (n == 0);
%% Ramp Signal
ramp_signal = (n >= 0) .* n;
%% Exponential Signal
%% Sine Signal
f = 0.1; % Frequency
sine_signal = sin(2*pi*f*n);
%% Cosine Signal
cosine_signal = cos(2*pi*f*n);
figure;
% Impulse Signal
subplot(3,2,1);
xlabel('n');
ylabel('Amplitude');
grid on;
% Step Signal
subplot(3,2,2);
xlabel('n');
ylabel('Amplitude');
grid on;
% Ramp Signal
subplot(3,2,3);
title('Ramp Signal');
xlabel('n');
ylabel('Amplitude');
grid on;
% Exponential Signal
subplot(3,2,4);
title('Exponential Signal');
xlabel('n');
ylabel('Amplitude');
grid on;
% Sine Signal
subplot(3,2,5);
title('Sine Signal');
xlabel('n');
ylabel('Amplitude');
grid on;
% Cosine Signal
subplot(3,2,6);
title('Cosine Signal');
xlabel('n');
ylabel('Amplitude');
grid on;
Orthogonality between two signals can be tested using the inner product of the signals. If
the inner product of two signals is zero, the signals are orthogonal. For discrete-time
signals x[n]x[n]x[n] and y[n]y[n]y[n], the inner product is defined as:
n = 0:10;
end
subplot(2,1,1);
xlabel('n');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
xlabel('n');
ylabel('Amplitude');
grid on;
N = 20;
% 1. Square wave
% 2. Sawtooth wave
% 3. Triangular wave
function Ck = compute_efs_coefficients(signal, t, T, N)
or k = -N:N
end
reconstructed_square = zeros(size(t));
reconstructed_sawtooth = zeros(size(t));
reconstructed_triangular = zeros(size(t));
for k = -N:N
end
figure;
subplot(3,2,1);
plot(t, square_wave);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(3,2,2);
plot(t, real(reconstructed_square));
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(3,2,3);
plot(t, sawtooth_wave);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(3,2,4);
plot(t, real(reconstructed_sawtooth));
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(3,2,5);
plot(t, triangular_wave);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(3,2,6);
plot(t, real(reconstructed_triangular));
xlabel('Time (t)');
ylabl('Amplitude');
grid on;
function Ck = compute_efs_coefficients(signal, t, T, N)
w0 = 2 * pi / T;
Ck = zeros(1, 2*N+1);
for k = -N:N
end
end
Ck = compute_efs_coefficients(x_t, t, T, N);
reconstructed_x_t = zeros(size(t));
for k = -N:N
figure;
subplot(2,1,1);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
disp(Ck);
% Define parameters
t = linspace(0, T, 1000);
an = zeros(1, N);
bn = zeros(1, N);
for n = 1:N
an(n) = (2/T) * trapz(t, x_t .* cos(n * w0 * t));bn(n) = (2/T) * trapz(t, x_t .* sin(n * w0 * t));
end
reconstructed_x_t = a0/2;
for n = 1:N
end
figure;
subplot(2,1,1);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
X_w = fftshift(fft(x_t));
x_t_reconstructed = ifft(ifftshift(X_w));
figure;
subplot(2, 1, 1);
plot(t, x_t, 'LineWidth', 2);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(2, 1, 2);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
% Display results
disp(x_t);
disp('FT (Shifted):');
disp(X_w);
disp('Reconstructed Signal:');
disp(x_t_reconstructed);
% Parameters
a = 2; % Scaling factor
% Time vector
X_omega = fftshift(fft(x_t));
X_a_omega = fftshift(fft(x_at));
% Frequency vector
N = length(t);
% Plotting
figure;
subplot(2, 1, 1);
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(2, 1, 2);
xlabel('Time (at)');
ylabel('Amplitude');
grid on;
figure;
subplot(2, 1, 1);
xlabel('Frequency (\omega)');
ylabel('Magnitude');
grid on;
xlim([-3*omega0, 3*omega0]);
subplot(2, 1, 2);
xlabel('Frequency (\omega)');
ylabel('Magnitude');
grid on;
xlim([-3*omega0, 3*omega0]);
clear;
syms t omega;
disp('-------------------------------------------');
disp('f(t):');
disp(f_t);
disp('g(t):');
disp(g_t);
disp('h(t) = f(t) * g(t):');
disp(h_t);