% Define the parameters
Fs = 1000; % Sampling frequency (Hz)
T = 1/Fs; % Sampling period (s)
L = 1000; % Length of the signal
t = (0:L-1)*T; % Time vector
% Create a sine wave signal
f = 50; % Frequency of the sine wave (Hz)
signal = 0.5*sin(2*pi*f*t) + randn(size(t))*0.1; % Sine wave + noise
% Compute the Fourier Transform
Y = fft(signal);
% Compute the two-sided spectrum
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1); % Single-sided spectrum
% Define the frequency domain
f = Fs*(0:(L/2))/L;
% Plot the results
figure;
subplot(2,1,1);
plot(t, signal);
title('Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2,1,2);
plot(f, P1);
title('Single-Sided Amplitude Spectrum of Signal');
xlabel('Frequency (Hz)');
ylabel('|P1(f)|');
grid on;
To embed this project on your website, copy the following code and paste it into your website's HTML: