MATLAB Code
MATLAB Code
Linear Convolution
Using Built-in Function
% Define two discrete signals
x = [1, 2, 3, 4];
h = [2, 1];
Auto-Correlation
Using Built-in Function
% Define a discrete signal
x = [1, 2, 3, 4];
figure;
xlabel('Time (t)');
grid on;
figure;
subplot(3, 1, 1);
xlabel('Samples');
ylabel('Amplitude');
subplot(3, 1, 2);
xlabel('Samples');
ylabel('Amplitude');
subplot(3, 1, 3);
xlabel('Samples');
ylabel('Amplitude');
for k = 0:N-1
for n = 0:N-1
end
end
disp(X);
for n = 0:N-1
for k = 0:N-1
end
disp(x_reconstructed);
figure;
subplot(3, 1, 1);
stem(0:N-1, x, 'filled');
xlabel('Sample Index');
ylabel('Amplitude');
subplot(3, 1, 2);
xlabel('Frequency Index');
ylabel('Magnitude');
subplot(3, 1, 3);
xlabel('Sample Index');
ylabel('Amplitude');
% Adjust layout
X_fft = fft(X_n);
X_ifft = ifft(X_fft);
figure;
subplot(3, 1, 1);
plot(n, X_n);
xlabel('Sample Index');
ylabel('Amplitude');
% Plot the magnitude spectrum of the FFT
subplot(3, 1, 2);
plot(f, abs(X_fft));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
subplot(3, 1, 3);
plot(n, real(X_ifft));
xlabel('Sample Index');
ylabel('Amplitude');
% Adjust layout
disp(y_circular_inbuilt);
for n = 1:N
for m = 1:N
if index < 0
end
end
end
disp(y_circular_manual);
% Sampling frequency
fs = 1000; % Hz
% Low-pass filter
% High-pass filter
% Band-pass filter
% Band-stop filter
figure;
figure;
figure;
figure;
% Sampling frequency
fs = 2000; % Hz
% Filter order
% Butterworth Filter
% Elliptic Filter
figure;
figure;
figure;
First experiment
%% Continuous-Time Signals
figure;
subplot(3, 1, 1);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3, 1, 2);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3, 1, 3);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
%% Discrete-Time Signals
figure;
subplot(3, 1, 1);
xlabel('n (Samples)');
ylabel('Amplitude');
grid on;
subplot(3, 1, 2);
xlabel('n (Samples)');
ylabel('Amplitude');
grid on;
subplot(3, 1, 3);
xlabel('n (Samples)');
ylabel('Amplitude');
grid on;
figure;
subplot(3, 1, 1);
xlabel('n (Samples)');
ylabel('Amplitude');
grid on;
subplot(3, 1, 2);
xlabel('n (Samples)');
ylabel('Amplitude');
grid on;
subplot(3, 1, 3);
xlabel('n (Samples)');
ylabel('Amplitude');
grid on;
Second experiment
% Scaling Transformation
% Filter Transformation
figure;
% Original Signal
subplot(5, 1, 1);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Scaled Signal
subplot(5, 1, 2);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Time-Shifted Signal
subplot(5, 1, 3);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Reversed Signal
subplot(5, 1, 4);
title('Time-Reversed Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Filtered Signal
subplot(5, 1, 5);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;