clear all , close all, clc

% Time axis: Sample period is 1 millisecond
t = -1:1/1024:1;
T=1; %УхнплйкЮ дйЬскейб чсьнпх рпх кЬнщ фзн гсбцйкЮ рбсЬуфбуз бсчЯжпнфбт брь фз чспнйкЮ уфйгмЮ 0
N=size(t,2); %Ухнплйкьт бсйимьт дейгмЬфщн
dt=1/2048 %=T/N
% A rectangular pulse of width 50 milliseconds
y = rectpuls(t,0.05);
figure(1)
subplot(3,1,1)
plot(t,y)
axis([-1 1 0 2])
title('Signal')
xlabel('time (seconds)')
% Discrete Fourier transform (via the Fast Fourier Transform)
Y=fft(y)


% Compute the amplitude of the spectrum and center it
df=1/T;
fs=1/dt;
f=-fs/2:df:fs/2;
subplot(3,1,2)

plot(f./1000,abs(fftshift(Y)))
title('Spectrum')
xlabel('frequency (Hz)')



f=0:df:fs;
subplot(3,1,3)
plot(f./1000,abs(Y));
title('Spectrum')
xlabel('frequency (Hz)')



% A rectangular pulse of width 100 milliseconds
y = rectpuls(t,0.1);
figure(2)
subplot(2,1,1)
plot(t,y)
axis([-1 1 0 2])
title('Signal')
xlabel('time (seconds)')

% Discrete Fourier transform (via the Fast Fourier Transform)
Y=fft(y)
% Compute the amplitude of the spectrum and center it
S = abs(fftshift(Y));

df=1/T;
fs=1/dt;

f=-fs/2:df:fs/2;

subplot(2,1,2)
plot(f./1000,S)
%axis([-1 1 0 100])
title('Spectrum')
xlabel('frequency (Hz)')

% A rectangular pulse of width 1000 milliseconds
y = rectpuls(t,1);
figure(3)
subplot(2,1,1)
plot(t,y)
axis([-1 1 0 2])
title('Signal')
xlabel('time (seconds)')

% Discrete Fourier transform (via the Fast Fourier Transform)
Y=fft(y)
% Compute the amplitude of the spectrum and center it
S = abs(fftshift(Y));

df=1/T;
fs=1/dt;

f=-fs/2:df:fs/2;

subplot(2,1,2)
plot(f./1000,S)
%axis([-1 1 0 100])
title('Spectrum')
xlabel('frequency (Hz)')
