Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

using Plots, FFTW, PlutoUI
3.4 s

This notebook explores the effect of sampling frequency on the DFT spectrum. The radio buttons below allow you to set the frequency for the basic sinusoid.

md"""This notebook explores the effect of sampling frequency on the DFT spectrum.
The radio buttons below allow you to set the frequency for the basic sinusoid."""
192 μs
Set base frequency
md"""##### Set base frequency"""
182 μs
@bind f Radio(["2" => "2 Hz", "4" => "4 Hz"], default="2")
78.1 ms

Parameter set up

begin
fs1 = 100
ts1 = 0:(1/fs1):π
fs2 = 2
ts2 = 0:(1/FS):π
md"""`Parameter set up`"""
end
5.8 ms

The plot below shows the original sinusoid at the frequency shown above along with a sampled version of it. The sampling rate can be set with the slider below

md""" The plot below shows the original sinusoid at the frequency shown above along with a sampled version of it. The sampling rate can be set with the slider below"""
186 μs
begin
fi = parse(Int32, f)
o_signal = sin.(2π*fi*ts2)
p11 = plot(ts1, sin.(2π*fi*ts1), label="Original", title="Original = $fi Hz, Dots sampling at $FS Hz")
p12 = scatter!(p11, ts2, o_signal, marker=:o, line=:false, label="Sampled")
end
137 ms

Set the sampling frequency using the slider below

md""" Set the sampling frequency using the slider below"""
175 μs
@bind FS Slider(100:-1:2)
38.1 ms

The plot below shows the magnitude spectrum of the signal. As you can see increasing the sampling frequency results in a sharper magnitude spectrum and cleaner peaks.

md""" The plot below shows the magnitude spectrum of the signal. As you can see increasing the sampling frequency results in a sharper magnitude spectrum and cleaner peaks."""
188 μs
begin
sF = fftshift(fft(o_signal))
freqs = fftfreq(length(o_signal), FS)
local mag = plot(fftshift(freqs), abs.(sF), title="Symmetric magnitude spectrum", label=false, xlim=(-8,8), ylim=(0, 120))
end
46.9 ms