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
2.1 s

Effect of aliasing

Now let us fix a few parameters and examine the effect of aliasing. Recall that for accurately capturing the frequency characteristics, we need to sample at atleast twice the frequency of the highest frequency component in the signal. Let the original signal be the 4 Hz sinusoid and let us sample it at 12 Hz (so three times the Nyquist)

md"""### Effect of aliasing
Now let us fix a few parameters and examine the effect of aliasing. Recall that for accurately capturing the frequency characteristics, we need to sample at atleast twice the frequency of the highest frequency component in the signal. Let the original signal be the 4 Hz sinusoid and let us sample it at 12 Hz (so three times the Nyquist)
"""
250 μs
Main.var"workspace#3".fixedParams
module fixedParams
using Plots, FFTW
ts1 = 0:(1/100):π
title = "Original = 4 Hz\nDots sampling at 12 Hz"
# signal = sin.(2π*fi*ts2) + sin.(2π*10*ts2)
ts3 = 0:(1/12):π
fx_signal = sin.(2π*4*ts3)
p1 = plot(ts1,sin.(2π*4*ts1), label="Original", title=title)
p2 = scatter!(p1, ts3, fx_signal, marker=:o, line=:false, label="Sampled")
fxFT = fftshift(fft(fx_signal))
freq = fftfreq(length(fx_signal), 12)
mag = plot(fftshift(freq), abs.(fxFT), label=false, title="Symm. magnitude spectrum")
pp = plot(p2, mag, layout=(1,2), size=(800,400))
end
391 ms
11.6 μs

The radio buttons below will add a different frequency sinewave to the original signal.

md"""The radio buttons below will add a different frequency sinewave to the original signal."""
208 μs
@bind adf Radio(["1" => "1 Hz", "2" => "2 Hz", "6" => "6 Hz", "10"=>"10 Hz"], default="1")
79.1 ms
begin
fs1 = 100
ts1 = 0:(1/fs1):π
title = "Dots sampling at 12 Hz"
nf = parse(Int32, adf)
signal(x) = sin.(2π*4*x) + sin.(2π*nf*x)
ts3 = 0:(1/12):π
fx_signal = signal(ts3)
p1 = plot(ts1,signal(ts1), label="Original", title=title)
p2 = scatter!(p1, ts3, fx_signal, marker=:o, line=:false, label="Sampled")
fxFT = fftshift(fft(fx_signal))
freq = fftfreq(length(fx_signal), 12)
mag = plot(fftshift(freq), abs.(fxFT), label=false, title="Magnitude Spectrum", xlim=(0, Inf))
pp = plot(p2, mag, layout=(1,2), size=(800,400))
end
137 ms

As you can see things are okay when we addeed a 1 Hz or 2 Hz sinewave to the original signal. However, as soon as we add a 6 Hz sine wave, we hit the limits. We no longer detect a peak. Then when we add a 10 Hz wave, the frequency is folded back and erroneously reported at 12-10 = 2 Hz.

md"""As you can see things are okay when we addeed a 1 Hz or 2 Hz sinewave to the original signal. However, as soon as we add a 6 Hz sine wave, we hit the limits. We no longer detect a peak. Then when we add a 10 Hz wave, the frequency is folded back and erroneously reported at 12-10 = 2 Hz."""
189 μs