20 lines
524 B
R
20 lines
524 B
R
x=c(1,2,3,4) # Our real signal
|
|
N=4 # Signal size
|
|
fs=10 # Sampling frequency
|
|
Xkn=function(k,n){x[n+1]*exp(-2i*pi*(k/N)*n)}
|
|
|
|
# Compute DFT:
|
|
X0=Xkn(0,0)+Xkn(0,1)+Xkn(0,2)+Xkn(0,3)
|
|
X1=Xkn(1,0)+Xkn(1,1)+Xkn(1,2)+Xkn(1,3)
|
|
X2=Xkn(2,0)+Xkn(2,1)+Xkn(2,2)+Xkn(2,3)
|
|
X3=Xkn(3,0)+Xkn(3,1)+Xkn(3,2)+Xkn(3,3)
|
|
|
|
X=c(X0,X1,X2,X3) # This is your final fft
|
|
|
|
f0=0/N*fs # k/N*fs
|
|
f1=1/N*fs
|
|
f2=2/N*fs
|
|
f3=3/N*fs
|
|
|
|
# Plot FFT:
|
|
plot(c(-f3,-f2,-f1,f0,f1,f2,f3),c(X3,X2,X1,X0,X1,X2,X3),type="l", xlab="Frequency (Hz)", ylab="Amplitude (Volt, db etc..)")
|