close all
Fs = 10000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 5000; % Length of signal
t = (0:L-1)*T*1; % Time vector
S = VarName8;
% Corrupt the signal with zero-mean white noise with a variance of 4.
X = S(1:5000) + 2.*randn(length(t),1);
% Plot the noisy signal in the time domain. It is difficult to identify the frequency components by looking at the signal X(t).
figure(1);
plot(1000*t,X)
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('t (milliseconds)')
ylabel('X(t)')
Y = fft(X);
% Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% Define the frequency domain f and plot the single-sided amplitude spectrum P1.
% The amplitudes are not exactly at 0.7 and 1, as expected, because of the added noise. On average,
% longer signals produce better frequency approximations.
figure(2);
f = Fs*(0:(L/2))/L;
plot(f,P1')
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
% Now, take the Fourier transform of the original, uncorrupted signal and retrieve the exact amplitudes, 0.7 and 1.0.
%