-
-
Save prydin/c92de7ab9e7e5b626d47f9789f383b97 to your computer and use it in GitHub Desktop.
AM Detection example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate test signal | |
t = linspace(0,120*pi, 1000) | |
baseband = cos(t/40) | |
carrier = cos(t) | |
modulated = carrier .* baseband | |
# Downshift and split into I and Q | |
fq_offset = 1.05 # Carrier and LO are off by 5% | |
i = cos(t*fq_offset) .* modulated | |
q = sin(t*fq_offset) .* modulated | |
lpf = fir1(51, 0.1) | |
# Filter signals | |
filtered_i = filter(lpf, 1, i) | |
filtered_q = filter(lpf, 1, q) | |
clf | |
subplot(4,1,1) | |
plot(t, baseband) | |
title("Input signal") | |
subplot(4,1,2) | |
plot(t, filtered_i) | |
title("I (unfiltered and filtered)") | |
ylabel("foo") | |
hold on | |
plot(t, i) | |
#plot(t, sign(filtered_i)) | |
subplot(4,1,3) | |
plot(t, filtered_q) | |
hold on | |
plot(t, q) | |
#plot(t, sign(filtered_q)) | |
title("Q (unfiltered and filtered)") | |
mag_sqr = (filtered_i.*filtered_i) + (filtered_q .* filtered_q) | |
mag = sqrt(mag_sqr) | |
filtered_mag = filter(lpf, 1, mag) | |
subplot(4,1,4) | |
plot(t, mag_sqr) | |
hold on | |
plot(t, mag) | |
# plot(t, sign(filtered_i) .* sign(filtered_q)) | |
#plot(t, filtered_i+filtered_q) | |
plot(t, filtered_mag) | |
title("Mag and mag squared") | |
holf off |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment