首页 > 解决方案 > How to Estimate a bandwidth of a Signal in Python

问题描述

Required Bandwidth to Calculate

How is it possible for me to calculate or estimate the bandwidth between the redlines. as well is is possilbe for me to change the actual line colour instead of scatter.

import numpy as np
from pylab import *
from rtlsdr import RtlSdr
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection
from matplotlib.colors import ListedColormap, BoundaryNorm


# Get a list of detected device serial numbers (str)
serial_numbers = RtlSdr.get_device_serial_addresses()
# Find the device index for a given serial number
device_index = RtlSdr.get_device_index_by_serial('00000001')

sdr = RtlSdr(device_index)

# configure device
sdr.sample_rate = 2.4e6
sdr.center_freq = 95.5e6
sdr.gain = 0

samples = sdr.read_samples(1024*1024)
sdr.close()


# use matplotlib to estimate and plot the PSD

[Pxx, freqs] = psd(samples, NFFT=1024, Fs=sdr.sample_rate/1e6, Fc=sdr.center_freq/1e6)

xlabel('Frequency (MHz)')
ylabel('Relative power (dB)')
show()

y = Pxx
x = freqs


# The x and y data to plot
plt.plot(freqs,Pxx)
y = Pxx
x = freqs
col = np.where(x<1,'k',np.where(y<0.008,'y','r'))
plt.scatter(x,y,c=col,s=5, linewidth=7)
plt.show()

# Find centre freq
max1 = Pxx.max()
print(max1)

max_index= np.argmax(Pxx)
print(max_index)

print(freqs[max_index])

# Estimate Bandwidth


# Filter

# Record the signal

# Compress <<

How is it possible for me to calculate or estimate the bandwidth between the redlines. as well is is possilbe for me to change the actual line colour instead of scatter.

The image above shows exactly what I want to calculate.

标签: pythonsignal-processing

解决方案


推荐阅读