% Generate a random signalfs = 1000; % Sampling frequencyt = 0:1/fs:1-1/fs; % Time vectorf1 = 50; % Frequency of the signalx = 0.7*sin(2*pi*f1*t) + 0.4*sin(2*pi*100*t); % Signal with two frequencies% Compute the Fourier Transforml = length(x);
NFFT = 2^nextpow2(l); % Next power of 2 from length of xY = fft(x, NFFT)/l;
f = fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrumfigure;
plot(f,2*abs(Y(1:NFFT/2+1)));
title('Single-Sided Amplitude Spectrum of x(t)');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');