0% found this document useful (0 votes)
2 views27 pages

SS Lab

The document outlines a series of MATLAB experiments focused on signal processing, including generating various signals, performing operations on signals, calculating Fourier series coefficients, and analyzing Fourier transforms. Each experiment includes MATLAB code for generating and manipulating signals, along with plotting results and displaying computed values such as energy and average power. The document serves as a comprehensive guide for implementing signal processing techniques using MATLAB.

Uploaded by

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

SS Lab

The document outlines a series of MATLAB experiments focused on signal processing, including generating various signals, performing operations on signals, calculating Fourier series coefficients, and analyzing Fourier transforms. Each experiment includes MATLAB code for generating and manipulating signals, along with plotting results and displaying computed values such as energy and average power. The document serves as a comprehensive guide for implementing signal processing techniques using MATLAB.

Uploaded by

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

Experiment 1:

Generate various Signals and Sequences: Periodic and Aperiodic, Unit Impulse, Unit
Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc function

MATLAB Code:

1. Unit Impulse

n = -10:10;
unit_impulse = n == 0;
figure;
stem(n, unit_impulse);
title('Unit Impulse Sequence');
xlabel('n');
ylabel('Amplitude');
grid on;
2. Unit Step
n = -10:10;
unit_step = n >= 0;
figure;
stem(n, unit_step);
title('Unit Step Sequence');
xlabel('n');
ylabel('Amplitude');
grid on;
3. Square Wave:

t = 0:0.01:1;
square_wave = square(2 * pi * 5 * t);
figure;
plot(t, square_wave);
title('Square Wave');
xlabel('t');
ylabel('Amplitude');
grid on;
4. Sawtooth Wave:

t = 0:0.01:1;
sawtooth_wave = sawtooth(2 * pi * 5 * t);
figure;
plot(t, sawtooth_wave);
title('Sawtooth Wave');
xlabel('t');
ylabel('Amplitude');
grid on;

5. Triangular Wave:
t = 0:0.01:1;
triangular_wave = sawtooth(2 * pi * 5 * t, 0.5);
figure;
plot(t, triangular_wave);
title('Triangular Wave');
xlabel('t');
ylabel('Amplitude');
grid on;
6. Sinusoidal Wave:

t = 0:0.01:1;
sinusoidal_wave = sin(2 * pi * 5 * t);
figure;
plot(t, sinusoidal_wave);
title('Sinusoidal Wave');
xlabel('t');
ylabel('Amplitude');
grid on;
7. Ramp Function:

t = -10:10;
ramp_function = t .* (t >= 0);
figure;
plot(t, ramp_function);
title('Ramp Function');
xlabel('t');
ylabel('Amplitude');
grid on;
8. Sinc Function:

t = -10:0.01:10;
sinc_function = sinc(t);
figure;
plot(t, sinc_function);
title('Sinc Function');
xlabel('t');
ylabel('Amplitude');
grid on;

9. Periodic Signal:

Here we use a sum of sinusoidal signals to create a periodic signal.

t = 0:0.01:1;
periodic_signal = sin(2 * pi * 5 * t) + sin(2 * pi * 10 * t);
figure;
plot(t, periodic_signal);
title('Periodic Signal');
xlabel('t');
ylabel('Amplitude');
grid on;

10.Aperiodic Signal

An example of an aperiodic signal is a Gaussian pulse.

t = -5:0.01:5;
aperiodic_signal = exp(-t.^2);
figure;
plot(t, aperiodic_signal);
title('Aperiodic Signal');
xlabel('t');
ylabel('Amplitude');
grid on;

Output Graphs:
Experiment 2:

Operations on Signals and Sequences: Addition, Multiplication, Scaling, Shifting,


Folding, Computation of Energy and Average Power.

MATLAB Code:
Here's a MATLAB script that demonstrates various operations on signals and
sequences, including addition, multiplication, scaling, shifting, folding, and the computation
of energy and average power.

% Define two example signals


n = -10:10; % Discrete time index
x1 = sin(0.2*pi*n); % Example signal 1
x2 = cos(0.2*pi*n); % Example signal 2

% Addition of signals
x_add = x1 + x2;

% Multiplication of signals
x_mult = x1 .* x2;

% Scaling of signals
a = 2; % Scaling factor
x_scaled = a * x1;

% Shifting of signals
k = 5; % Shift amount
x_shifted = circshift(x1, k);

% Folding (time-reversal) of signals


x_folded = fliplr(x1);

% Computation of energy of a signal


energy = sum(abs(x1).^2);

% Computation of average power of a signal


N = length(x1); % Number of samples
avg_power = sum(abs(x1).^2) / N;

% Plotting the signals


figure;
subplot(3, 2, 1);
stem(n, x1, 'b');
title('Signal x1');
xlabel('n');
ylabel('x1[n]');
subplot(3, 2, 2);
stem(n, x2, 'r');
title('Signal x2');
xlabel('n');
ylabel('x2[n]');

subplot(3, 2, 3);
stem(n, x_add, 'k');
title('Addition of x1 and x2');
xlabel('n');
ylabel('x1[n] + x2[n]');

subplot(3, 2, 4);
stem(n, x_mult, 'g');
title('Multiplication of x1 and x2');
xlabel('n');
ylabel('x1[n] * x2[n]');

subplot(3, 2, 5);
stem(n, x_scaled, 'm');
title(['Scaling of x1 by ', num2str(a)]);
xlabel('n');
ylabel('a * x1[n]');

subplot(3, 2, 6);
stem(n, x_shifted, 'c');
title(['Shifting of x1 by ', num2str(k), ' samples']);
xlabel('n');
ylabel('x1[n-k]');

figure;
subplot(2, 1, 1);
stem(n, x_folded, 'y');
title('Folding (Time-reversal) of x1');
xlabel('n');
ylabel('x1[-n]');

% Display computed values


disp(['Energy of x1: ', num2str(energy)]);
disp(['Average power of x1: ', num2str(avg_power)]);

Output :
Energy of x1: 10
Average power of x1: 0.47619

Output Graphs:
Experiment 3:
Write a program to find the trigonometric & exponential Fourier series coefficients
of a rectangular periodic signal. Reconstruct the signal by combining the Fourier
series coefficients with appropriate weightings- Plot the discrete spectrum of the
signal.

Matlab Code:

To find the trigonometric and exponential Fourier series coefficients of a rectangular


periodic signal, reconstruct the signal, and plot the discrete spectrum, you can follow these
steps. Here's a MATLAB script that demonstrates this process:

% Define the rectangular periodic signal parameters


T = 2; % Period of the signal
T1 = 0.5; % Duration of the rectangular pulse in one period
N = 10; % Number of harmonics for reconstruction
omega0 = 2*pi/T; % Fundamental angular frequency

% Time vector
t = linspace(-T, T, 1000);

% Define the rectangular periodic signal


x = @(t) (abs(mod(t + T/2, T) - T/2) <= T1/2) * 1;

% Evaluate the signal over one period


x_t = arrayfun(x, t);

% Plot the original signal


figure;
subplot(3, 1, 1);
plot(t, x_t);
title('Original Rectangular Periodic Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;

% Compute the Fourier series coefficients (exponential form)


a0 = (1/T) * integral(x, -T/2, T/2);
an = zeros(1, N);
bn = zeros(1, N);

for n = 1:N
% Compute the coefficients a_n and b_n for trigonometric Fourier series
an(n) = (2/T) * integral(@(t) x(t).*cos(n*omega0*t), -T/2, T/2);
bn(n) = (2/T) * integral(@(t) x(t).*sin(n*omega0*t), -T/2, T/2);
end

% Reconstruction of the signal using Fourier series coefficients


x_reconstructed = a0 * ones(size(t));
for n = 1:N
x_reconstructed = x_reconstructed + an(n) * cos(n*omega0*t) + bn(n) *
sin(n*omega0*t);
end

% Plot the reconstructed signal


subplot(3, 1, 2);
plot(t, x_reconstructed);
title('Reconstructed Signal using Fourier Series');
xlabel('Time');
ylabel('Amplitude');
grid on;

% Compute the exponential Fourier series coefficients


cn = zeros(1, 2*N+1);

for k = -N:N
cn(k + N + 1) = (1/T) * integral(@(t) x(t).*exp(-1i*k*omega0*t), -T/2, T/2);
end

% Plot the discrete spectrum (magnitude of exponential Fourier series coefficients)


subplot(3, 1, 3);
stem(-N:N, abs(cn));
title('Discrete Spectrum (Magnitude of Exponential Fourier Series Coefficients)');
xlabel('Harmonic Number');
ylabel('Magnitude');
grid on;

% Display computed coefficients


disp('Fourier series coefficients (a_n):');
disp(an);
disp('Fourier series coefficients (b_n):');
disp(bn);
disp('Exponential Fourier series coefficients (c_n):');
disp(cn);

Output:
Fourier series coefficients (a_n):
0.4502 0.3183 0.1501 0.0000 -0.0900 -0.1061 -0.0643 -0.0000 0.0500 0.0637

Fourier series coefficients (b_n):


1.0e-16 *

0.0000 -0.0396 0.1366 -0.0000 0.0000 -0.0304 -0.1432 -0.0002 -0.0737 0.0651

Exponential Fourier series coefficients (c_n):


Columns 1 through 5

0.0318 + 0.0000i 0.0250 + 0.0000i -0.0000 + 0.0000i -0.0322 - 0.0000i -0.0531 + 0.0000i

Columns 6 through 10

-0.0450 + 0.0000i 0.0000 + 0.0000i 0.0750 - 0.0000i 0.1592 + 0.0000i 0.2251 + 0.0000i

Columns 11 through 15

0.2500 + 0.0000i 0.2251 - 0.0000i 0.1592 - 0.0000i 0.0750 + 0.0000i 0.0000 - 0.0000i

Columns 16 through 20

-0.0450 - 0.0000i -0.0531 - 0.0000i -0.0322 + 0.0000i -0.0000 - 0.0000i 0.0250 - 0.0000i

Column 21

0.0318 - 0.0000i

Output Graphs:

Experiment 4:
Write a program to find Fourier transform of a given signal. Plot its amplitude and
phase spectrum.

Here's a MATLAB script that computes the Fourier transform of a given signal and plots its
amplitude and phase spectrum:

MATLAB Code:
% Define the signal
t = -5:0.01:5; % Time vector
x = @(t) rectpuls(t, 2); % Example signal: Rectangular pulse of width 2

% Evaluate the signal over the time vector


x_t = x(t);

% Compute the Fourier transform of the signal


X_f = fftshift(fft(x_t));
f = linspace(-0.5, 0.5, length(t)) * (1 / (t(2) - t(1))); % Frequency vector

% Compute amplitude and phase spectrum


amplitude_spectrum = abs(X_f);
phase_spectrum = angle(X_f);

% Plot the signal


figure;

subplot(3, 1, 1);
plot(t, x_t);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

% Plot the amplitude spectrum


subplot(3, 1, 2);
plot(f, amplitude_spectrum);
title('Amplitude Spectrum');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
grid on;

% Plot the phase spectrum


subplot(3, 1, 3);
plot(f, phase_spectrum);
title('Phase Spectrum');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
grid on;
% Display Fourier transform properties
disp('Fourier Transform Properties:');
disp(['Max Amplitude: ', num2str(max(amplitude_spectrum))]);
disp(['Min Phase: ', num2str(min(phase_spectrum))]);
disp(['Max Phase: ', num2str(max(phase_spectrum))]);

Output:
Fourier Transform Properties:
Max Amplitude: 200
Min Phase: -3.1353
Max Phase: 3.1353

Output Graphs:
Experiment 5:

Write a program to convolve two discrete time sequences. Plot all the sequences.

Here's a MATLAB script that convolves two discrete-time sequences and plots the original
sequences along with their convolution result

MATLAB Code:

% Define two discrete-time sequences


n1 = 0:10; % Time index for first sequence
x1 = [1 2 3 4 5 4 3 2 1 0 0]; % Example sequence 1

n2 = 0:5; % Time index for second sequence


x2 = [1 -1 1 -1 1 -1]; % Example sequence 2

% Perform convolution
y = conv(x1, x2);

% Time index for the convolution result


ny = (n1(1) + n2(1)):(n1(end) + n2(end));

% Plot the sequences


figure;

subplot(3, 1, 1);
stem(n1, x1, 'b', 'filled');
title('Sequence x1[n]');
xlabel('n');
ylabel('x1[n]');
grid on;

subplot(3, 1, 2);
stem(n2, x2, 'r', 'filled');
title('Sequence x2[n]');
xlabel('n');
ylabel('x2[n]');
grid on;

subplot(3, 1, 3);
stem(ny, y, 'k', 'filled');
title('Convolution Result y[n] = x1[n] * x2[n]');
xlabel('n');
ylabel('y[n]');
grid on;

Output Graphs:
Experiment 6:

Write a program to find autocorrelation and cross correlation of given sequences.

Here is a MATLAB script that computes and plots the autocorrelation and cross-correlation
of two given sequences.

MATLAB Code:

% Define two discrete-time sequences


n1 = 0:10; % Time index for first sequence
x1 = [1 2 3 4 5 4 3 2 1 0 0]; % Example sequence 1

n2 = 0:5; % Time index for second sequence


x2 = [1 -1 1 -1 1 -1]; % Example sequence 2

% Compute autocorrelation of x1
auto_corr_x1 = xcorr(x1);

% Compute autocorrelation of x2
auto_corr_x2 = xcorr(x2);

% Compute cross-correlation between x1 and x2


cross_corr = xcorr(x1, x2);

% Time indices for correlations


n_auto_x1 = -length(x1) + 1:length(x1) - 1;
n_auto_x2 = -length(x2) + 1:length(x2) - 1;
n_cross = -max(length(x1), length(x2)) + 1:max(length(x1), length(x2)) - 1;

% Plot the sequences and their correlations


figure;

subplot(3, 2, 1);
stem(n1, x1, 'b', 'filled');
title('Sequence x1[n]');
xlabel('n');
ylabel('x1[n]');
grid on;

subplot(3, 2, 2);
stem(n2, x2, 'r', 'filled');
title('Sequence x2[n]');
xlabel('n');
ylabel('x2[n]');
grid on;

subplot(3, 2, 3);
stem(n_auto_x1, auto_corr_x1, 'b', 'filled');
title('Autocorrelation of x1[n]');
xlabel('Lag');
ylabel('R_{x1x1}[k]');
grid on;

subplot(3, 2, 4);
stem(n_auto_x2, auto_corr_x2, 'r', 'filled');
title('Autocorrelation of x2[n]');
xlabel('Lag');
ylabel('R_{x2x2}[k]');
grid on;

subplot(3, 2, 5:6);
stem(n_cross, cross_corr, 'k', 'filled');
title('Cross-Correlation between x1[n] and x2[n]');
xlabel('Lag');
ylabel('R_{x1x2}[k]');
grid on;

Output Graph:

Experiment 7:
Write a program to verify Linearity and Time Invariance properties of a given
Continuous System.

MATLAB Code:
% Define the continuous system as a function
% Example: A simple system where y(t) = 2 * x(t)
system = @(t, x) 2 * x;

% Define the time vector


t = -10:0.01:10;

% Define input signals


x1 = @(t) sin(t);
x2 = @(t) cos(t);

% Define linear combination coefficients


a1 = 1.5;
a2 = -0.5;

% Compute system response to individual inputs


y1 = system(t, x1(t));
y2 = system(t, x2(t));

% Compute system response to linear combination of inputs


x_combined = @(t) a1 * x1(t) + a2 * x2(t);
y_combined = system(t, x_combined(t));

% Compute linear combination of individual responses


y_combined_expected = a1 * y1 + a2 * y2;

% Verify linearity
linearity_error = max(abs(y_combined - y_combined_expected));

if linearity_error < 1e-6


disp('System is linear.');
else
disp('System is not linear.');
end

% Define time shift


tau = 2;

% Compute shifted input


x1_shifted = @(t) x1(t - tau);
x2_shifted = @(t) x2(t - tau);

% Compute system response to shifted input


y1_shifted = system(t, x1_shifted(t));
y2_shifted = system(t, x2_shifted(t));

% Compute shifted response of the original input


y1_expected_shifted = system(t - tau, x1(t));
y2_expected_shifted = system(t - tau, x2(t));

% Verify time invariance


time_invariance_error_1 = max(abs(y1_shifted - y1_expected_shifted));
time_invariance_error_2 = max(abs(y2_shifted - y2_expected_shifted));

if time_invariance_error_1 < 1e-6 && time_invariance_error_2 < 1e-6


disp('System is time-invariant.');
else
disp('System is not time-invariant.');
end

% Plot results
figure;

subplot(3, 2, 1);
plot(t, x1(t), 'b');
title('Input x1(t)');
xlabel('Time');
ylabel('Amplitude');
grid on;

subplot(3, 2, 2);
plot(t, y1, 'r');
title('Output y1(t)');
xlabel('Time');
ylabel('Amplitude');
grid on;

subplot(3, 2, 3);
plot(t, x2(t), 'b');
title('Input x2(t)');
xlabel('Time');
ylabel('Amplitude');
grid on;

subplot(3, 2, 4);
plot(t, y2, 'r');
title('Output y2(t)');
xlabel('Time');
ylabel('Amplitude');
grid on;
subplot(3, 2, 5);
plot(t, x_combined(t), 'b');
title('Combined Input a1*x1(t) + a2*x2(t)');
xlabel('Time');
ylabel('Amplitude');
grid on;

subplot(3, 2, 6);
plot(t, y_combined, 'r', t, y_combined_expected, 'g--');
title('Combined Output vs Expected Output');
xlabel('Time');
ylabel('Amplitude');
legend('Combined Output', 'Expected Output');
grid on;

figure;

subplot(2, 2, 1);
plot(t, x1_shifted(t), 'b');
title('Shifted Input x1(t-\tau)');
xlabel('Time');
ylabel('Amplitude');
grid on;

subplot(2, 2, 2);
plot(t, y1_shifted, 'r', t, y1_expected_shifted, 'g--');
title('Shifted Output vs Expected Shifted Output for x1(t)');
xlabel('Time');
ylabel('Amplitude');
legend('Shifted Output', 'Expected Output');
grid on;

subplot(2, 2, 3);
plot(t, x2_shifted(t), 'b');
title('Shifted Input x2(t-\tau)');
xlabel('Time');
ylabel('Amplitude');
grid on;

subplot(2, 2, 4);
plot(t, y2_shifted, 'r', t, y2_expected_shifted, 'g--');
title('Shifted Output vs Expected Shifted Output for x2(t)');
xlabel('Time');
ylabel('Amplitude');
legend('Shifted Output', 'Expected Output');
grid on;
Output:
System is linear.
System is not time-invariant.

Output Graphs:

Experiment 8:
Write a program to generate discrete time sequence by sampling a continuous time
signal. Show that with sampling rates less than Nyquist rate, aliasing occurs while
reconstructing the signal.

MATLAB Code:
% Define the continuous-time signal
Fs = 1000; % Sampling frequency for the original continuous-time signal
t = 0:1/Fs:1; % Time vector
f0 = 50; % Frequency of the continuous-time signal
x_continuous = sin(2*pi*f0*t); % Continuous-time signal

% Define sampling rates


Fs1 = 100; % Above Nyquist rate (2*f0)
Fs2 = 30; % Below Nyquist rate

% Sample the continuous-time signal


n1 = 0:1/Fs1:1;
x_sampled1 = sin(2*pi*f0*n1);

n2 = 0:1/Fs2:1;
x_sampled2 = sin(2*pi*f0*n2);

% Reconstruct the signal from the sampled data


x_reconstructed1 = interp1(n1, x_sampled1, t, 'linear');
x_reconstructed2 = interp1(n2, x_sampled2, t, 'linear');

% Plot the continuous-time signal


figure;
subplot(3, 1, 1);
plot(t, x_continuous, 'b');
title('Continuous-Time Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

% Plot the sampled signal and reconstructed signal (above Nyquist rate)
subplot(3, 1, 2);
stem(n1, x_sampled1, 'r');
hold on;
plot(t, x_reconstructed1, 'g--');
title('Sampling and Reconstruction (Above Nyquist Rate)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Sampled Signal', 'Reconstructed Signal');
grid on;

% Plot the sampled signal and reconstructed signal (below Nyquist rate)
subplot(3, 1, 3);
stem(n2, x_sampled2, 'r');
hold on;
plot(t, x_reconstructed2, 'g--');
title('Sampling and Reconstruction (Below Nyquist Rate)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Sampled Signal', 'Reconstructed Signal');
grid on;

% Display sampling rates


disp(['Original sampling rate: ', num2str(Fs), ' Hz']);
disp(['Above Nyquist sampling rate: ', num2str(Fs1), ' Hz']);
disp(['Below Nyquist sampling rate: ', num2str(Fs2), ' Hz']);

Output :
Original sampling rate: 1000 Hz
Above Nyquist sampling rate: 100 Hz
Below Nyquist sampling rate: 30 Hz

Output Graphs:

Experiment 9:
Write a program to generate Complex Gaussian noise and find its mean, variance,
Probability Density Function (PDF) and Power Spectral Density (PSD).

MATLAB Code:

% Define the continuous-time signal


Fs = 1000; % Sampling frequency for the original continuous-time signal
t = 0:1/Fs:1; % Time vector
f0 = 50; % Frequency of the continuous-time signal
x_continuous = sin(2*pi*f0*t); % Continuous-time signal

% Define sampling rates


Fs1 = 100; % Above Nyquist rate (2*f0)
Fs2 = 30; % Below Nyquist rate

% Sample the continuous-time signal


n1 = 0:1/Fs1:1;
x_sampled1 = sin(2*pi*f0*n1);

n2 = 0:1/Fs2:1;
x_sampled2 = sin(2*pi*f0*n2);

% Reconstruct the signal from the sampled data


x_reconstructed1 = interp1(n1, x_sampled1, t, 'linear');
x_reconstructed2 = interp1(n2, x_sampled2, t, 'linear');

% Plot the continuous-time signal


figure;
subplot(3, 1, 1);
plot(t, x_continuous, 'b');
title('Continuous-Time Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

% Plot the sampled signal and reconstructed signal (above Nyquist rate)
subplot(3, 1, 2);
stem(n1, x_sampled1, 'r');
hold on;
plot(t, x_reconstructed1, 'g--');
title('Sampling and Reconstruction (Above Nyquist Rate)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Sampled Signal', 'Reconstructed Signal');
grid on;

% Plot the sampled signal and reconstructed signal (below Nyquist rate)
subplot(3, 1, 3);
stem(n2, x_sampled2, 'r');
hold on;
plot(t, x_reconstructed2, 'g--');
title('Sampling and Reconstruction (Below Nyquist Rate)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Sampled Signal', 'Reconstructed Signal');
grid on;

% Display sampling rates


disp(['Original sampling rate: ', num2str(Fs), ' Hz']);
disp(['Above Nyquist sampling rate: ', num2str(Fs1), ' Hz']);
disp(['Below Nyquist sampling rate: ', num2str(Fs2), ' Hz']);
Original sampling rate: 1000 Hz
Above Nyquist sampling rate: 100 Hz
Below Nyquist sampling rate: 30 Hz
>> % Parameters
N = 10000; % Number of samples
mu = 0; % Mean of Gaussian noise
sigma = 1; % Standard deviation of Gaussian noise

% Generate complex Gaussian noise


real_part = mu + sigma * randn(N, 1);
imag_part = mu + sigma * randn(N, 1);
complex_noise = real_part + 1i * imag_part;

% Calculate mean and variance


mean_value = mean(complex_noise);
variance_value = var(complex_noise);

% Calculate PDF
[real_pdf, real_x] = ksdensity(real(complex_noise)); % Real part
[imag_pdf, imag_x] = ksdensity(imag(complex_noise)); % Imaginary part

% Calculate PSD using the periodogram method


[psd, freq] = periodogram(complex_noise, [], [], 1);

% Display mean and variance


disp(['Mean: ', num2str(mean_value)]);
disp(['Variance: ', num2str(variance_value)]);

% Plot PDF
figure;

subplot(2, 1, 1);
plot(real_x, real_pdf, 'b');
hold on;
plot(imag_x, imag_pdf, 'r');
title('Probability Density Function (PDF)');
xlabel('Value');
ylabel('Density');
legend('Real Part', 'Imaginary Part');
grid on;

% Plot PSD
subplot(2, 1, 2);
plot(freq, 10*log10(psd), 'k');
title('Power Spectral Density (PSD)');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;

You might also like