复数信号采样率要求分析
2018-02-25 本文已影响0人
小石头爸爸
%pylab inline
pylab.rcParams['figure.figsize'] = (10, 6)
from scipy.signal import *
Populating the interactive namespace from numpy and matplotlib
def gensig(sr, fs):
"""
sr - sample rate @MHz
fs - signal frequency @MHz
"""
#sample time
st = 1/sr #@us
t = arange(1024)*st
#signal frequency
fs = 5 #@MHz
vi = cos(2*pi*fs*t)
vq = sin(2*pi*fs*t)
return vi, vq
def checkfft(x, tname, full, sr):
fout = fft.fft(x)
if not full:
fout = fft.fftshift(fout)
amp = 20*log10(abs(fout) + 1e-5)
#fft range is [-sample_frequency/2, sample_frequency/2]
nfft = len(amp)
if full:
fin = sr*(arange(nfft)/float(nfft))
else:
fin = sr*(arange(nfft)/float(nfft) - 0.5)
figure()
plot(fin, amp)
grid(True)
title(tname)
#5MHz signal @40MHz sample rate
sr = 40.0
fs = 5.0
vi, vq = gensig(sr, fs)
#now check the fft of real signal
checkfft(vi, 'real signal', False, sr)
#now check fft of complex signal
checkfft(vi+1j*vq, 'complex signal', True, sr)
#5MHz @6MHz sample rate
sr = 6.0
vi, vq = gensig(sr, fs)
#now check the fft of real signal
checkfft(vi, 'real signal', False, sr)
#now check fft of complex signal
checkfft(vi+1j*vq, 'complex signal', True, sr)
output_1_0.png
output_1_1.png
output_1_2.png
output_1_3.png