From d705228b483fe35e5e9fed7f236b353d135bfdcc Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 2 Nov 2023 06:41:29 +0100 Subject: [PATCH] Minor changes --- source/signal_processing/code/dft.R | 20 ++++++++++++++++++++ source/signal_processing/dft.rst | 1 + 2 files changed, 21 insertions(+) create mode 100644 source/signal_processing/code/dft.R diff --git a/source/signal_processing/code/dft.R b/source/signal_processing/code/dft.R new file mode 100644 index 0000000..3420387 --- /dev/null +++ b/source/signal_processing/code/dft.R @@ -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..)") diff --git a/source/signal_processing/dft.rst b/source/signal_processing/dft.rst index 59df92c..72ec952 100644 --- a/source/signal_processing/dft.rst +++ b/source/signal_processing/dft.rst @@ -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