MATLAB: Plot Signals A & B, Combined Y, and Y with Gaussian Noise Using Subplot

MATLAB Illustration

lot two signals (A and B) sampled at 1 kHz for 100 ms, their combination Y = A + B, and Y with added white Gaussian noise (variance = 2), using subplots.

Key MATLAB Steps:

  1. Define sampling: fs = 1000; t = 0:1/fs:0.1-1/fs; (100 samples).
  2. Create signals: e.g., A = sin(2*pi*50*t); B = 0.7*sin(2*pi*200*t);.
  3. Combine: Y = A + B;.
  4. Add noise: Y_noisy = Y + sqrt(2)*randn(size(t)); (variance = 2).
  5. Use figure and subplot(3,1,...):
    • Top: Plot A and B (different colors/styles).
    • Middle: Clean Y.
    • Bottom: Noisy Y.
  6. Add grid on, titles, labels (time in ms), and legend.

    % Parameters
    fs = 1000;          % Sampling frequency: 1 kHz
    T = 0.1;            % Total time: 100 ms
    t = 0:1/fs:T-1/fs;  % Time vector (100 samples)

    % Signal A: Example - 50 Hz sine wave
    A = sin(2*pi*50*t);

    % Signal B: Example - 200 Hz sine wave
    B = 0.7 * sin(2*pi*200*t);

    % Combined signal Y = A + B
    Y = A + B;

    % Add white Gaussian noise with variance 2 (standard deviation = sqrt(2) ≈ 1.414)
    noise = sqrt(2) * randn(size(t));   % White Gaussian noise with variance 2
    Y_noisy = Y + noise;

    % Create figure with subplots
    figure('Name', 'Signal Plotting', 'NumberTitle', 'off');

    % Subplot 1: Original signals A and B
    subplot(3,1,1);
    plot(t*1000, A, 'b', 'LineWidth', 1.5); hold on;
    plot(t*1000, B, 'r--', 'LineWidth', 1.5);
    grid on;
    title('Signal A (blue) and Signal B (red)');
    xlabel('Time (ms)');
    ylabel('Amplitude');
    legend('A (50 Hz)', 'B (200 Hz)');
    hold off;

    % Subplot 2: Combined signal Y = A + B (clean)
    subplot(3,1,2);
    plot(t*1000, Y, 'g', 'LineWidth', 1.5);
    grid on;
    title('Combined Signal Y = A + B (clean)');
    xlabel('Time (ms)');
    ylabel('Amplitude');

    % Subplot 3: Combined signal Y with white Gaussian noise (variance = 2)
    subplot(3,1,3);
    plot(t*1000, Y_noisy, 'k', 'LineWidth', 1.2);
    grid on;
    title('Signal Y with White Gaussian Noise (variance = 2)');
    xlabel('Time (ms)');
    ylabel('Amplitude');

    % Adjust layout
    sgtitle('Bidirectional AC-DC Converter Control Signals Simulation Example');
    set(gcf, 'Position', [100 100 900 600]);   

    What this code does:

    • Samples two example signals (50 Hz and 200 Hz sine waves) at 1 kHz for 100 ms.
    • Combines them into Y = A + B.
    • Adds white Gaussian noise with variance = 2 to Y.
    • Uses three subplots:
      1. Original signals A and B.
      2. Clean combined signal Y.
      3. Noisy version of Y.
    • Time axis in milliseconds for clarity.

What Our Students Say

★★★★★

“I got full marks on my MATLAB assignment! The solution was perfect and delivered well before the deadline. Highly recommended!”

Aditi Sharma, Mumbai
★★★★☆

“Quick delivery and excellent communication. The team really understood the problem and provided a great solution. Will use again.”

John M., Australia

Latest Blogs

Explore how MATLAB Solutions has helped clients achieve their academic and research goals through practical, tailored assistance.

MATLAB R2026a: What's New in the 2026 Release? Major Features & Highlights

MATLAB R2026a (the first major release of 2026) is now available, and it brings a strong mix of AI-powered tools, deeper language integrations, improved productivity features, and performance boosts.