Last active
April 14, 2020 04:02
-
-
Save nihalpasham/f4c3877fbcba030143498abb551e3343 to your computer and use it in GitHub Desktop.
Despreading the signal and visualising data via a Fourier transform
This file contains hidden or 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
from scipy.fftpack import fft, fftfreq, fftshift | |
from scipy import signal | |
from scipy.signal import butter,filtfilt | |
k = 38389 # one of the peaks chosen randomly | |
sample_rate = 48000 | |
nyq_rate = sample_rate / 2.0 | |
order = 9 | |
cutoff = 560 | |
despread_re = np.multiply(us1, re[ k : k + len(us1) ]) | |
despread_im = np.multiply(us1, im[ k : k + len(us1) ]) | |
# Apply a low pass filter with the cut-off at 560 hz seems to work well. | |
normal_cutoff = cutoff / nyq_rate | |
# Get the filter coefficients | |
b, a = butter(order, normal_cutoff, btype='low', analog=False) | |
y = filtfilt(b, a, despread_re) | |
f = signal.resample(y, 512) | |
N = 512 | |
# sample spacing | |
T = 1.0 / 12000.0 | |
yf = fft(f) | |
xf = fftfreq(N, T) | |
xf = fftshift(xf) | |
yplot = fftshift(yf) | |
plt.figure(figsize=(30,10)) | |
plt.plot(xf, 1.0/N * np.abs(yplot)) | |
plt.xticks(np.arange(min(xf), max(xf)+1, 500.0)) | |
plt.grid() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment