how to run fast fourier transform in matlab

main.m
% Generate a random signal
fs = 1000; % Sampling frequency
t = 0:1/fs:1-1/fs; % Time vector
f1 = 50; % Frequency of the signal
x = 0.7*sin(2*pi*f1*t) + 0.4*sin(2*pi*100*t); % Signal with two frequencies

% Compute the Fourier Transform
l = length(x);
NFFT = 2^nextpow2(l); % Next power of 2 from length of x
Y = fft(x, NFFT)/l;
f = fs/2*linspace(0,1,NFFT/2+1);

% Plot single-sided amplitude spectrum
figure;
plot(f,2*abs(Y(1:NFFT/2+1)));
title('Single-Sided Amplitude Spectrum of x(t)');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');
533 chars
19 lines

gistlibby LogSnag