82.9k views
1 vote
Write a MATLAB script to compute the signal-to-noise ratio (SNR) of a 100 ms rectangular pulse sampled for 2 s(−1,1) at 10kHz and embedded in a white Gaussian noise with standard deviation 0.05 . Plot the signal with and without the noise in the same window. (Hint: use snr function)

1 Answer

2 votes

Final answer:

The student's question involves writing a MATLAB script to calculate the signal-to-noise ratio (SNR) of a 100 ms rectangular pulse with white Gaussian noise and plotting both signals. A sample MATLAB script that performs the required calculations and plots is provided.

Step-by-step explanation:

The student asked to write a MATLAB script to compute the signal-to-noise ratio (SNR) for a 100 ms rectangular pulse sampled for 2 seconds at a rate of 10 kHz and embedded in white Gaussian noise with a standard deviation of 0.05. Additionally, they need to plot the signal with and without noise in the same window using MATLAB.

Here's a MATLAB script that can achieve this:

fs = 10000; % Sampling frequency
T = 2; % Duration of the signal

% Create time vector
t = 0:1/fs:T-1/fs;

% Create the pulse
pulse_duration = 0.1;
pulse = rectpulse(ones(1, pulse_duration*fs), fs);
signal = [pulse zeros(1, fs*T - length(pulse))];

% Generate white Gaussian noise
std_dev = 0.05;
noise = std_dev*randn(1, length(t));

% Add noise to the pulse to create noisy signal
noisy_signal = signal + noise;

% Compute the SNR
SNR = snr(signal, noise);

% Plot the signals
figure;
plot(t, signal, 'b', t, noisy_signal, 'r');
title(['Signal with and without noise (SNR = ' num2str(SNR) ' dB)']);
legend('Signal','Signal with Noise');
xlabel('Time (s)');
ylabel('Amplitude');

This script first defines the sampling frequency and the total duration for the signal. It then creates the pulse and the white Gaussian noise before adding them to generate a noisy signal. The SNR is calculated using the snr function. Finally, it plots both the original and noisy signals on the same graph, demonstrating the effect of the noise.

User Danialk
by
8.3k points