# how to make fft of rectangular function?

14 visualizzazioni (ultimi 30 giorni)
YEON HWEE BAE il 2 Dic 2017
Risposto: Tilkesh il 28 Mar 2022
Ts = 0.01; N=2000; t=-20:Ts:(N-1)*Ts; T = 1; fs=1/Ts; f=0:fs/N:(N-1)/N*fs; x1 = rectpuls(t, T); xk=fft(x1); figure(1); plot(t,x1); figure(2); plot(0:N-1, xk); figure(3); plot(f, 1/N*abs(xk));
figure1,2 are not found. what is the problem? how can i fix it?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Star Strider il 2 Dic 2017
Small error in figure(3). You do not need figure(2).
This works:
Ts = 0.01; N=2000; t=-20:Ts:(N-1)*Ts;
T = 1;
fs=1/Ts;
f=0:fs/N:(N-1)/N*fs;
x1 = rectpuls(t, T);
xk=fft(x1);
figure(1); plot(t,x1)2
figure(3); plot(f, 1/N*abs(xk(1:length(f))));
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Parth Patel il 16 Apr 2020
Modificato: Parth Patel il 16 Apr 2020
In this program , i asume, f = frequency.
can the value of frequency be zero?
f=0:fs/N:(N-1)/N*fs;
Star Strider il 16 Apr 2020
Yes.
A zero frequency signal is d-c, usually present as a constant offset in a signal that is otherwise varying. The d-c component is the mean of the signal.

Accedi per commentare.

Tilkesh il 28 Mar 2022
function y = rect(x, D)
% function y = rect(x, D)
if nargin == 1, D = 1;
x = abs(x);
y = double(x<D/2);
y(x == D/2) = 0.5;
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Discrete Fourier and Cosine Transforms in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!