简体   繁体   中英

How to Generate a Root-Raised cosine impulse response in the time domain in Python

I want to generate an impulse response of a root raised cosine that can be used as a pulse shape filter for a certain set of data.

I have looked at the commPy library specifically at the rrcosfilter function, but it does not seem to work for some or other reason. I hav tried to code the frequency response and then inverse Fourier transform to get it, but that was alos unsuccesfull.

I'm usiing a linspace to generate a time reference which I then use in a for loop to graph the response. The sampling Frequency is 2.4e6.


Beta = 0.5
Ts = 1/100000


x = np.linspace(0, 1000/2.4e6, 1/2.4e6 )
root_raised_cosine_time = []

for i in range(len(x)):
    if x[i] == 0:
        root_raised_cosine_time.append((1/Ts)*(1 + Beta*((4/np.pi - 1))))

    elif (x[i] == Ts/(4*Beta) or x[i] == -Ts/(4*Beta)):
        root_raised_cosine_time.append((Beta/(Ts*np.sqrt(2)))*((1 + 2/np.pi)*((np.sin(np.pi/(4*Beta))) + (1-(2/np.pi)*np.cos(np.pi/(4*Beta))))))

    else:
        root_raised_cosine_time.append((1/Ts)*((np.sin((np.pi*x[i]/Ts)*(1-Beta))+(4*Beta)*(x[i]/Ts)*np.cos((np.pi*x[i]/Ts)*(1+Beta)))/((np.pi*x[i])/Ts)(1-((4*Beta*x[i])/Ts)**2)))

A graph needs to be plotted that looks very similar to sinc function. At the moment, the root raised cosine is not plotting.

You are calling np.linspace wrong. You need to specify the stop value and the number of elements in the array, not the step and end value.

If you look at help on np.linspace in a Python shell:

help(np.linspce)

Help on function linspace in module numpy.core.function_base:

linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
    Return evenly spaced numbers over a specified interval.

    Returns `num` evenly spaced samples, calculated over the
    interval [`start`, `stop`].

    The endpoint of the interval can optionally be excluded.

Try

x = np.linspace(0, 1/2.4e6, 1000)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM