why the fft results of these functions are not what I expect?

4 次查看(过去 30 天)
I have three functions; a sinusoid, square and sawtooth. The fft of sine is what we expect in fourier domain. But I expect to see a sinc function for the square. But why its not what I expect?
close all;
clear all;
fs=1e5;
a=-0.01;
b=0.01;
t = a:1/fs:b;
x = sin(1000*2*pi*t);
y = sawtooth(500*2*pi*t);
z = square(2000*2*pi*t);
N=length(x);
figure, subplot(1,3,1), plot(t,x);xlim([a/10 b/10])
subplot(1,3,2), plot(t,y);xlim([a/10 b/10])
subplot(1,3,3), plot(t,z);xlim([a/10 b/10])
A = 2*fftshift(abs(fft(x))/N);
b = 2*fftshift(abs(fft(y)))/N;
c = 2*fftshift(abs(fft(z)))/N;
if mod(N,2) == 0 % N is even
f = ( (-N/2) : ((N-2)/2) )/N*fs;
else % N is odd
f = ( (-(N-1)/2) : ((N-1)/2) )/N*fs;
end
figure
plot(f, c); xlim([-fs fs])
figure
plot(f, b);xlim([-fs fs])
figure
plot(f, A);xlim([-fs fs])
  6 个评论

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by