why the fft results of these functions are not what I expect?
조회 수: 2 (최근 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 Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!