0% found this document useful (0 votes)
5 views10 pages

Rajoni Signal Lab

Uploaded by

ehshan.orchid
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)
5 views10 pages

Rajoni Signal Lab

Uploaded by

ehshan.orchid
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/ 10

Experiment 5: Fourier Transform of Continuous-Time Signals

% Fourier Transform using Numerical Integration

clc; clear; close all;

% Time specifications

Fs = 1000; % Sampling frequency

dt = 1/Fs; % Time step

t = -10:dt:10; % Time vector (from -1s to 1s)

% Define signal x(t)

x = exp(-abs(t)); % Example signal: e^(-|t|)

% Frequency specifications

f = -100:1:100; % Frequency range

X = zeros(size(f)); % Initialize Fourier Transform

% Numerical integration for each frequency

for k = 1:length(f)

X(k) = trapz(t, x .* exp(-1j*2*pi*f(k)*t));

end

% Plot time-domain signal

figure;

subplot(2,1,1);

plot(t, x, 'b','LineWidth',1.5);

xlabel('Time (s)');
ylabel('x(t)');

title('Time Domain Signal');

grid on;

% Plot frequency spectrum

subplot(2,1,2);

plot(f, abs(X), 'r','LineWidth',1.5);

xlabel('Frequency (Hz)');

ylabel('|X(f)|');

title('Fourier Transform (Numerical Integration)');

grid on;

Experiment 6: Laplace transform and system response.

clc; clear; close all;

%% ==============================

% PART 1: Numerical Laplace Transform

% ==============================

% Define the signal x(t) = e^(-2t)

t_values = 0:0.01:5; % Time: 0 to 5 seconds

x_t = exp(-2 * t_values); % Signal definition

s_values = 0.1:0.1:10; % Range of s-values

X_s = zeros(size(s_values));

% Numerical Laplace Transform using trapezoidal rule


for i = 1:length(s_values)

current_s = s_values(i);

integrand = x_t .* exp(-current_s * t_values);

X_s(i) = trapz(t_values, integrand);

end

% Plot Numerical Laplace Transform

figure;

plot(s_values, abs(X_s), 'b', 'LineWidth', 1.5);

title('Numerical Laplace Transform |X(s)|');

xlabel('s');

ylabel('|X(s)|');

grid on;

%% ==============================

% PART 2: System Response

% ==============================

tau = 1; % Time constant

% Input: Unit Step

u_t = ones(size(t_values));

% Output: Step Response y(t) = 1 - exp(-t/tau)

y_t = 1 - exp(-t_values / tau);

% Plot system response


figure;

plot(t_values, u_t, 'b--', 'LineWidth', 1.5, 'DisplayName', 'Input u(t)');

hold on;

plot(t_values, y_t, 'r-', 'LineWidth', 1.5, 'DisplayName', 'Output y(t)');

title('First-Order System Step Response');

xlabel('Time (s)');

ylabel('Amplitude');

legend('show');

grid on;

% Fix axis limits

xlim([0 5]); % Time axis from 0 to 5 sec

ylim([0 2]); % Amplitude axis from 0 to 2

Experiment 7: sampling theorem and aliasing.

% Sampling Theorem Demonstration with Two Sampling Rates (0 to 2 sec)

clc;

clear;

close all;

% Original continuous-time signal

fsignal = 5; % Signal frequency (Hz)

t = 0:0.001:2; % Time vector from 0 to 2 sec

x = sin(2*pi*fsignal*t); % Original signal

% --- First Sampling (higher fs, Nyquist satisfied) ---


fs1 = 12; % Sampling frequency 1

Ts1 = 1/fs1;

n1 = 0:Ts1:2;

x_n1 = sin(2*pi*fsignal*n1);

% --- Second Sampling (lower fs, aliasing likely) ---

fs2 = 8; % Sampling frequency 2

Ts2 = 1/fs2;

n2 = 0:Ts2:2;

x_n2 = sin(2*pi*fsignal*n2);

% Plot

figure;

% Original signal

plot(t, x, 'k--', 'LineWidth', 1); hold on;

% First sampling (Nyquist satisfied)

stem(n1, x_n1, 'b', 'filled', 'LineWidth', 1.2);

% Second sampling (Aliasing case)

stem(n2, x_n2, 'r', 'filled', 'LineWidth', 1.2);

% Formatting

title('Sampling Theorem Demonstration with Two Sampling Rates');

xlabel('Time (s)');
ylabel('Amplitude');

legend('Original Signal','Sampled Signal (fs=12 Hz)','Sampled Signal (fs=8 Hz)');

axis([0 2 -1.2 1.2]); % Extended axis from 0 to 2 sec

grid on;

Experiment 8 :Z transform and discrete time system analysis.

% Experiment 8: Z-Transform and Discrete-Time System Analysis

clc; clear; close all;

% Define discrete-time sequence x[n]

n = 0:10; % index from 0 to N

x = (0.8).^n; % example sequence x[n] = (0.8)^n

% Z values on the unit circle (z = e^(j*theta))

theta = linspace(0, 2*pi, 500);

z = exp(1j*theta);

% Compute Z-transform: X(z) = sum x[n] * z^(-n)

Xz = zeros(size(z));

for k = 1:length(z)

Xz(k) = sum(x .* (z(k)).^(-n));

end

% --- Plot 1: Discrete sequence x[n] ---

figure;

stem(n, x, 'filled', 'LineWidth', 1.5);


xlabel('n'); ylabel('x[n]');

title('Discrete Sequence x[n]');

grid on;

% --- Plot 2: Magnitude of X(z) on the unit circle ---

figure;

plot(theta, abs(Xz), 'LineWidth', 2);

xlabel('Frequency (rad/sample)');

ylabel('|X(e^{j\omega})|');

title('Magnitude of Z-Transform on Unit Circle');

grid on;

Experiment 9: LTI system analysis using difference equations.

% Experiment 9: LTI System Analysis using Difference Equations

clc; clear; close all;

% Define coefficients of the difference equation

a1 = 0.5; % example coefficient

a2 = 0.25; % example coefficient

b0 = 1; % input coefficient

b1 = 0.5; % input coefficient

% Form coefficient vectors for filter()

b = [b0 b1]; % numerator coefficients (x terms)

a = [1 a1 a2]; % denominator coefficients (y terms, with y[n], y[n-1], y[n-2])


% Input signal (example: unit step)

n = 0:20;

x = ones(size(n)); % unit step signal

% System response using filter()

y = filter(b, a, x);

% --- Plot input and output ---

figure;

subplot(2,1,1);

stem(n, x, 'filled', 'LineWidth', 1.5);

xlabel('n'); ylabel('x[n]');

title('Input Signal (Unit Step)');

ylim([0 1.2]); % y-axis from 0 to 1.2

yticks(0:0.2:1.2); % tick marks at 0.2 increments

grid on;

subplot(2,1,2);

stem(n, y, 'filled', 'LineWidth', 1.5);

xlabel('n'); ylabel('y[n]');

title('Output Signal (System Response)');

ylim([0 1.2]); % y-axis from 0 to 1.2

yticks(0:0.2:1.2); % tick marks at 0.2 increments

grid on;
Experiment 10: Filter design frequency response analysis

% Experiment 10: Filter Design and Frequency Response Analysis

clc; clear; close all;

%% Define impulse response h[n]

h = [1 2 3 4]; % Example impulse response (can be changed as needed)

%% Frequency range (from -pi to pi)

omega = linspace(-pi, pi, 500);

%% Compute DTFT: H(e^j?) = ? h[n] e^(-j?n)

H = zeros(size(omega));

for n = 1:length(h)

H = H + h(n) * exp(-1j * omega * (n-1)); % (n-1) because MATLAB index starts at 1

end

%% Plot Magnitude and Phase Response

figure;

subplot(2,1,1);

plot(omega, abs(H), 'LineWidth', 1.5);

xlabel('\omega (rad/sample)');

ylabel('|H(e^{j\omega})|');

title('Magnitude Response');

grid on;
subplot(2,1,2);

plot(omega, angle(H), 'LineWidth', 1.5);

xlabel('\omega (rad/sample)');

ylabel('?H(e^{j\omega}) [rad]');

title('Phase Response');

grid on;

%% Display Result

disp('Impulse Response h[n] = ');

disp(h);

You might also like