Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
66 views

Example 1: DFT of Sine Waveform: (One Cycle, Two Cycles and Seven Cycles)

The document contains examples demonstrating the discrete Fourier transform (DFT) of sine waveforms with different frequencies and DC components. It shows that the DFT of a one cycle sine wave is non-zero at the first and last indices, representing the lowest frequencies. For waveforms with multiple cycles, the DFT is non-zero at indices corresponding to the frequencies of each component. It also shows the DFT of a sampled waveform at the Nyquist frequency accumulates differences and has a peak at the last index.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Example 1: DFT of Sine Waveform: (One Cycle, Two Cycles and Seven Cycles)

The document contains examples demonstrating the discrete Fourier transform (DFT) of sine waveforms with different frequencies and DC components. It shows that the DFT of a one cycle sine wave is non-zero at the first and last indices, representing the lowest frequencies. For waveforms with multiple cycles, the DFT is non-zero at indices corresponding to the frequencies of each component. It also shows the DFT of a sampled waveform at the Nyquist frequency accumulates differences and has a peak at the last index.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Example 1: DFT of Sine Waveform (one cycle, two cycles and seven cycles)

N = 64;
n = 0:N-1;
w = 2*pi/N;

x1 = sin(n*w);
subplot(321); stem(x1); title('input signal, one cycle');
xlabel('time index, n \rightarrow'); ylabel('x1(n) \rightarrow');

X1k = fft(x1);
subplot(322); stem(abs(X1k)); title('DFT of input signal, non-zero at k=1 and k=63');
xlabel('frequency index, k \rightarrow'); ylabel('X1(k) \rightarrow');

x2 = sin(2*n*w);
subplot(323); stem(x2); title('input signal, two cycles');
xlabel('time index, n \rightarrow'); ylabel('x2(n) \rightarrow');

X2k = fft(x2);
subplot(324); stem(abs(X2k)); title('DFT of input signal, non-zero at k=2 and k=62');
xlabel('frequency index, k \rightarrow'); ylabel('X2(k) \rightarrow');

x3 = sin(7*n*w);
subplot(325); stem(x3); title('input signal, seven cycles');
xlabel('time index, n \rightarrow'); ylabel('x3(n) \rightarrow');

X3k = fft(x3);
subplot(326); stem(abs(X3k)); title('DFT of input signal, non-zero at k=7 and k=57');
xlabel('frequency index, k \rightarrow'); ylabel('X3(k) \rightarrow');
input signal, one cycle DFT of input signal, non-zero at k=1 and k=63
1 40

0.5 30

0 20

X1(k)
x1(n)

-0.5 10

-1 0
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
time index, n frequency index, k
input signal, two cycles DFT of input signal, non-zero at k=2 and k=62
1 40

0.5 30

0 20

X2(k)
x2(n)

-0.5 10

-1 0
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
time index, n frequency index, k
input signal, seven cycles DFT of input signal, non-zero at k=7 and k=57
1 40

0.5 30

0 20
X3(k)
x3(n)

-0.5 10

-1 0
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
time index, n frequency index, k

Example 2: DFT of Sine Waveform with two components and a DC term


N = 64;
n = 0:N-1;
w = 2*pi/N;

x1 = sin(n*w) + 5;
subplot(221); stem(x1);
title('one cycle added with 5 dc component, i.e., every sample added with value 5 (64x5 = 320)');
xlabel('time index, n \rightarrow'); ylabel('x1(n) \rightarrow');

X1k = fft(x1);
subplot(222); stem(abs(X1k));
title('DFT of input signal, non-zero at k=1 and k=63 with DC component 320');
xlabel('frequency index, k \rightarrow'); ylabel('X1(k) \rightarrow');

x2 = sin(2*n*w) + (4*sin(7*n*w)) + 3;
subplot(223); stem(x2);
title('input signal, sin(2*n*w) + (4*sin(7*n*w)) + 3');
xlabel('time index, n \rightarrow'); ylabel('x2(n) \rightarrow');

X2k = fft(x2);
subplot(224); stem(abs(X2k));
title('DFT of input signal, non-zero at k=2&62 and k=7&57 with DC component 3x64=192');
xlabel('frequency index, k \rightarrow'); ylabel('X2(k) \rightarrow');
one cycle added with 5 dc component, i.e., every sample added with value 5 (64x5 = 320) DFT of input signal, non-zero at k=1 and k=63 with DC component 320
6 350

5 300

250
4
200
3

X1(k)
x1(n)

150
2
100

1 50

0 0
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
time index, n frequency index, k

input signal, sin(2*n*w) + (4*sin(7*n*w)) + 3 DFT of input signal, non-zero at k=2&62 and high peak at k=7&57 with DC component 3x64=192
8 200

6
150

4
100
X2(k)
x2(n)

50
0

-2 0
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
time index, n frequency index, k

Example 3: DFT of the highest/Nyquist frequency component


N = 32;
x = zeros(N,1);
x(1) = 1;
for n = 2:N
x(n) = -1*x(n-1);
end
Xk = fft(x);

subplot(221); stem(x);
title('input signal (N=32), sampled at Fs/2 which is the Nyqusit/highest freq');
xlabel('time index, n \rightarrow'); ylabel('x(n) \rightarrow');

subplot(222); stem(Xk);
title('peak at Fs/2, i.e., at k*Fs/N = 16*Fs/32 where differences are accumulated');
xlabel('frequency index, k \rightarrow'); ylabel('X(k) \rightarrow');

N1 = 128;
y = zeros(N1,1);
y(1) = 1;
for n1 = 2:N1
y(n1) = -1*y(n1-1);
end
Yk = fft(y);

subplot(223); stem(y);
title('input signal (N=128), sampled at Fs/2 which is the Nyqusit/highest freq');
xlabel('time index, n \rightarrow'); ylabel('y(n) \rightarrow');

subplot(224); stem(Yk);
title('peak at Fs/2, i.e., at k*Fs/N = 64*Fs/128 where differences are accumulated');
xlabel('frequency index, k \rightarrow'); ylabel('Y(k) \rightarrow');
input signal (N=32), sampled at Fs/2 which is the Nyqusit/highest freq peak at Fs/2, i.e., at k*Fs/N = 16*Fs/32 where differences are accumulated
1 35

30
0.5
25

20
0

X(k)
x(n)

15

10
-0.5
5

-1 0
0 5 10 15 20 25 30 35 0 5 10 15 20 25 30 35
time index, n frequency index, k

input signal (N=128), sampled at Fs/2 which is the Nyqusit/highest freq peak at Fs/2, i.e., at k*Fs/N = 64*Fs/128 where differences are accumulated
1 140

120
0.5
100

80
0
Y(k)
y(n)

60

40
-0.5
20

-1 0
0 20 40 60 80 100 120 140 0 20 40 60 80 100 120 140
time index, n frequency index, k

Example 4: Noisy Waveform Restoration


N = 256;
n = 0:N-1;
w = 2*pi/N;

x = 7*cos(3*n*w) + 13*sin(6*n*w);
subplot(321); plot(x); title('original signal');
xlabel('time index, n \rightarrow'); ylabel('x(n) \rightarrow');

Xk = fft(x);
subplot(322); stem(abs(Xk)); title('DFT peaks at k = 3 and 6');
xlabel('frequency index, k \rightarrow'); ylabel('X(k) \rightarrow');

xn = x + 10*randn(1,N);
subplot(323); plot(xn); title('original signal+noise');
xlabel('time index, n \rightarrow'); ylabel('xn(n) \rightarrow');

Xnk = fft(xn);
subplot(324); stem(abs(Xnk)); title('DFT peaks at k = 3 and 6');
xlabel('frequency index, k \rightarrow'); ylabel('Xn(k) \rightarrow');

iz = find(abs(Xnk)/N*2 < 4);


Xnk(iz) = zeros(size(iz));
subplot(325); stem(abs(Xnk)); title('DFT peaks at k = 3 and 6 are to be retained');
xlabel('frequency index, k \rightarrow'); ylabel('Xn(k) \rightarrow');

xr = ifft(Xnk);
subplot(326); plot(real(xr)); title('recovered signal');
xlabel('time index, n \rightarrow'); ylabel('xr(n) \rightarrow');
original signal DFT peaks at k = 3 and 6
20 2000

10 1500

0 1000

X(k)
x(n)

-10 500

-20 0
0 50 100 150 200 250 300 0 50 100 150 200 250 300
time index, n frequency index, k
original signal+noise DFT peaks at k = 3 and 6
40 2000

20 1500

0 1000

Xn(k)
xn(n)

-20 500

-40 0
0 50 100 150 200 250 300 0 50 100 150 200 250 300
time index, n frequency index, k
DFT peaks at k = 3 and 6 are to be retained recovered signal
2000 20

1500 10

1000 0
Xn(k)

xr(n)

500 -10

0 -20
0 50 100 150 200 250 300 0 50 100 150 200 250 300
frequency index, k time index, n

Example 5: DFT of zero inserted signal


>> x = [4 3 2 1];

>> fft(x)

ans = { 10, 2-2j, 2, 2+2j }

>> y = [4 0 3 0 2 0 1 0];

>> fft(y)

ans = { 10, 2-2j, 2, 2+2j, 10, 2-2j, 2, 2+2j }

Proof:
N N
1 1
2 2
 x ( 2n) W  x(2n  1)W
(2n)k (2n 1)k
N  N
Y(k) = n 0 n 0
DFT of even DFT of odd

N N
1 1
2 2
 x ( 2n) W N
nk
  0. W N
(2n 1)k

= n 0 2 n 0
N
1
2
 x ( 2n) W N
nk

= n 0 = DFT of even = X(k)


2
Y(k) = X(k), k = 0 to 7
= { X(0), X(1), X(2), X(3), X(4), X(0), X(1), X(2), X(3) }
____________________________________

Similarly,

>> y = [4 0 0 3 0 0 2 0 0 1 0 0];
>> fft(y)

ans = { 10, 2-2j, 2, 2+2j, 10, 2-2j, 2, 2+2j, 10, 2-2j, 2, 2+2j }

Example 6: DFT of repeat data


>> x = [4 3 2 1];
>> fft(x)

ans = { 10, 2-2j, 2 2+2j }

>> y = [4 3 2 1 4 3 2 1];
>> fft(y)

ans = { 20, 0, 4-4j, 0, 4, 0, 4+4j, 0 }

Proof:
N
1
2 N 1

 x ( n) W  x ( n) W
nk nk
N  N
n 0 N
n
Y(k) = 2
DFT of first 4 samples DFT of second 4 samples

N N N N
1 n  N 1 1 n 1
2 2 N 2 2 N
 x(n)WN   x(n)WN 
nk (n  ) k nk nk k
 x(n) WN 2  x(n) WN WN 2
n 0 N N n 0 n0
n 
= 2 2 =
N N N
1 n 1 1
2 2 2
 x ( n) W N
nk
  x ( n) W N
nk
(-1) k  x ( n) W N
nk
{1  (1) k }
Y(k) = n0 n0 = n 0

k even :
N N
1 1
2 2
 x ( n) W  x ( n) W
nk nk
N {1  (1) 2 k } N {1  1}
Y(2k) = n 0 = n 0 = 2 X(k)

k odd :
N N
1 1
2 2
 x ( n) W  x ( n) W
nk nk
N {1  (1) 2 k 1 } N {1  1}
Y(2k +1) = n0 = n 0 =0
Y(k) = X(k), k = 0 to 7
= { 2X(0), 0, 2X(1), 0, 2X(2), 0, 2X(3), 0}
____________________________________
Similarly,

>> y = [4 3 2 1 4 3 2 1 4 3 2 1];
>> fft(y)

ans = { 30, 0, 0, 6-6j, 0, 0, 6, 0, 0, 6+6j, 0, 0}

Example 7: DFT of weighted impulse, dc, and sampled at Fs/2


Type of data Time domain data, x(n) DFT of time domain data, X(k)
weighted { 2, 0, 0, 0 } { 2, 2, 2, 2 }
impulse { 8, 0, 0, 0 } { 8, 8, 8, 8 }

dc { 2, 2, 2, 2 } { 8, 0, 0, 0 }
{ 8, 8, 8, 8 } { 32, 0, 0, 0}

{ 2, -2, 2, -2 } { 0, 0, 8, 0 }
differences are accumulated at Fs/2, i.e., at k=4/2=2

Sampled at {8, -8, 8, -8 } { 0, 0, 32, 0 }

Fs/2 data {8, -8, 8, -8, 8, -8, 8, -8} { 0, 0, 0, 0, 64, 0, 0, 0 }


differences are accumulated at Fs/2, i.e., at k=8/2=4

Example 8: The FFT as a Sample Interpolator


N = 32;
n = 0:N-1;
w = 2*pi/N;

x = sin(n*w);
subplot(321); stem(x); title('input signal, one cycle');
xlabel('time index, n \rightarrow'); ylabel('x(n) \rightarrow');

Xk = fft(x);
subplot(322); stem(abs(Xk)); title('DFT of input signal, X(1) = X(32-1) = X(31) = 16');
xlabel('frequency index, k \rightarrow'); ylabel('X(k) \rightarrow');

xi = [x ; zeros(1,N)];
xi = reshape(xi, 2*N, 1);
subplot(323); stem(xi); title('zero inserted signal');
xlabel('time index, n \rightarrow'); ylabel('xi(n) \rightarrow');

Xik = fft(xi);
subplot(324); stem(abs(Xik)); title('Xi(k) = X(k), where k = 0 to 63 (periodicity property)');
% Xi(0) = X(0), Xi(1) = X(1), Xi(2) = X(2).... Xi(31) = X(31), Xi(32) = X(0), % Xi(33) = X(1), Xi(34) = X(2), .... Xi(63) = X(31).
xlabel(' frequency index, k \rightarrow'); ylabel('Xi(k) \rightarrow');

Xik(32) = 0;
Xik(34) = 0;

subplot(325); stem(abs(fi));
title('Interpolation with one cycle, i.e., k = 1 and k = 63 values are to be retained');
xlabel(' frequency index, k \rightarrow'); ylabel('Y(k) \rightarrow');

xi = 2*real(ifft(fi));
subplot(326); stem(xi); title('Interpolated output signal');
xlabel('time index, n \rightarrow'); ylabel('y(n) \rightarrow');
input signal, one cycle DFT of input signal, X(1) = X(32-1) = X(31) = 16
1 20

0.5 15

0 10

X(k)
x(n)

-0.5 5

-1 0
0 5 10 15 20 25 30 35 0 5 10 15 20 25 30 35
time index, n frequency index, k
zero inserted signal Xi(k) = X(k), where k = 0 to 63 (periodicity property)
1 20

0.5 15

0 10

Xi(k)
xi(n)

-0.5 5

-1 0
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
time index, n frequency index, k
Interpolation with one cycle, i.e., k = 1 and k = 63 values are to be retained Interpolated output signal
20 1

15 0.5

10 0
Y(k)

y(n)

5 -0.5

0 -1
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
frequency index, k time index, n

Repeat Example 8: The FFT as a Sample Interpolator (with two cycles)


N = 32;
n = 0:N-1;
w = 2*pi/N;

x = sin(2*n*w);
subplot(321); stem(x); title('input signal, two cycles');
xlabel('time index, n \rightarrow'); ylabel('x(n) \rightarrow');

Xk = fft(x);
subplot(322); stem(abs(Xk)); title('DFT of input signal, X(2) = X(32-2) = X(30) = 16');
xlabel('frequency index, k \rightarrow'); ylabel('X(k) \rightarrow');

xi = [x ; zeros(1,N)];
xi = reshape(xi, 2*N, 1);
subplot(323); stem(xi); title('zero inserted signal');
xlabel('time index, n \rightarrow'); ylabel('xi(n) \rightarrow');

Xik = fft(xi);
subplot(324); stem(abs(Xik)); title('Xi(k) = X(k), where k = 0 to 63 (periodicity property)');
% Xi(0) = X(0), Xi(1) = X(1), Xi(2) = X(2).... Xi(31) = X(31), Xi(32) = X(0),
% Xi(33) = X(1), Xi(34) = X(2), .... Xi(63) = X(31).
xlabel('frequency index, k \rightarrow'); ylabel('Xi(k) \rightarrow');

Xik(31) = 0;
Xik(35) = 0;

subplot(325); stem(abs(Xik));
title('Interpolation with one cycle, i.e., k = 1 and k = 63 values are to be retained');
xlabel('frequency index, k \rightarrow'); ylabel('Y(k) \rightarrow');

xi = 2*real(ifft(Xik));
subplot(326); stem(xi); title('Interpolated output signal');
xlabel('time index, n \rightarrow'); ylabel('y(n) \rightarrow');
input signal, two cycles DFT of input signal, X(2) = X(32-2) = X(30) = 16
1 20

0.5 15

0 10

X(k)
x(n)

-0.5 5

-1 0
0 5 10 15 20 25 30 35 0 5 10 15 20 25 30 35
time index, n frequency index, k
zero inserted signal Xi(k) = X(k), where k = 0 to 63 (periodicity property)
1 20

0.5 15

0 10

Xi(k)
xi(n)

-0.5 5

-1 0
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
time index, n frequency index, k
Interpolation with one cycle, i.e., k = 1 and k = 63 values are to be retained Interpolated output signal
20 1

15 0.5

10 0
Y(k)

y(n)

5 -0.5

0 -1
0 10 20 30 40 50 60 70 0 10 20 30 40 50 60 70
frequency index, k time index, n

You might also like