Minor changes
This commit is contained in:
parent
a67f6f9d3e
commit
d705228b48
2 changed files with 21 additions and 0 deletions
20
source/signal_processing/code/dft.R
Normal file
20
source/signal_processing/code/dft.R
Normal file
|
@ -0,0 +1,20 @@
|
|||
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..)")
|
|
@ -44,3 +44,4 @@ In depth example
|
|||
|
||||
Let's take a discrete signal :math:`\vec{x}=\{1,2,3,4\}`, sampled at a frequency :math:`f_s=10 Hz`.
|
||||
|
||||
.. literalinclude:: code/dft.R
|
||||
|
|
Loading…
Add table
Reference in a new issue