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

MATLAB Illustration

To plot two signals (Signal A and Signal B) sampled at 1 kHz for 100 ms, their combination Y = A + B, and the combined signal with added white Gaussian noise (variance = 2) using subplots in MATLAB, follow the complete solution below.

Key MATLAB Steps

  • Define Sampling Parameters: Set fs = 1000 Hz and total time T = 0.1 s (100 ms). Create time vector t = 0:1/fs:T-1/fs (100 samples).
  • Create Signals: Generate 50 Hz sine wave A = sin(2*pi*50*t) and 200 Hz sine wave B = 0.7*sin(2*pi*200*t).
  • Combine Signals: Calculate Y = A + B.
  • Add White Gaussian Noise: Add noise with variance = 2 (standard deviation = sqrt(2) ≈ 1.414): Y_noisy = Y + sqrt(2)*randn(size(t)).
  • Subplot Layout: Use subplot(3,1,...) to plot individual signals, clean combined signal, and noisy signal.

Complete MATLAB Code

MATLAB
% 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 sub
plot(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) sub
plot(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) sub
plot(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 sg
title('Bidirectional AC-DC Converter Control Signals Simulation Example');
set(gcf, 'Position', [100 100 900 600]);

Explanation of Code Execution

  • Samples two signals (50 Hz and 200 Hz sine waves) at 1 kHz for a 100 ms window (100 total samples).
  • Combines both signals linearly into Y = A + B.
  • Generates white Gaussian noise scaled by sqrt(2) to achieve noise variance = 2 and adds it to Y.
  • Organizes visualization into three stacked subplots:
    • Top subplot: Overlaid signals A (blue) and B (red dashed).
    • Middle subplot: Clean combined signal Y.
    • Bottom subplot: Combined signal Y corrupted with noise.
  • Scales the time axis by 1000 to display time in milliseconds (ms).

Need Expert Guidance with MATLAB or Simulink?

Our 500+ PhD engineers provide verified MATLAB code, custom Simulink models, and 1-on-1 tutoring with Turnitin plagiarism reports.

Verified Feedback

What Engineering Students Say

Real feedback from students across top engineering universities worldwide.

Verified Student

“I got full marks on my MATLAB DSP assignment! The filter design code was completely vectorized, the frequency response plots were exact, and the delivery was 8 hours before my deadline. Highly recommended!”

AS

Aditi Sharma

IIT Bombay • Signal Processing Coursework
Verified Student

“Our Simulink EV powertrain model had severe algebraic loop and solver errors. The MATLABSolutions team fixed the solver configuration in 4 hours and provided an annotated scope diagram. Lifesaver for my final year!”

JM

John M.

Monash University, Australia • Simulink Dynamic Model
Technical Knowledge Base

Latest MATLAB Guides & Tutorials

Explore deep-dive technical articles written by our engineering team to master complex MATLAB & Simulink topics.

MATLAB Guide 5 Min Read

Run Convolutional Neural Networks on ARM Cortex-M with MATLAB

Why Run CNNs on Cortex-M Processors? ARM Cortex-M cores power millions of edge sensors, industrial controllers, and medical wearables. Running 1D or 2D Convolutional N...

MATLAB Guide 5 Min Read

INT8 Deep Learning Quantization in MATLAB for Embedded Systems

The Memory Wall on Edge Microcontrollers Standard neural networks store weights and compute activations using single-precision floating point (32-bit float...