clc;clear;
Fs = 1028;
T = 1/Fs;
L = 1028;
t = (0:L-1)*T;
S =4*sin(2*pi*400*t)+2.5*sin(2*pi*150*t);
Y = fft(S);
f = Fs*(0:(L/2))/L;
figure;
plot(f, 2*abs(Y(1:L/2+1)/L));
figure;
plot(-Fs/2:Fs/L:Fs/2-Fs/L,fftshift(abs(Y))/L);
myfft(S,Fs,1);
function [f,Y] = myfft(data,Fs,is_plot)
if nargin < 3
is_plot = true;
end
x=data;
N = length(x);
df=Fs/(N-1);
f=(0:N-1)*df;
Y=fft(x(1:N))/N*2;
if is_plot
g = figure;
figure(g);
plot(f(1:N/2),abs(Y(1:N/2)));
axis normal;
end
end