Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rrcosfilter with Fs=3 #39

Open
philn16 opened this issue Aug 2, 2019 · 1 comment
Open

rrcosfilter with Fs=3 #39

philn16 opened this issue Aug 2, 2019 · 1 comment

Comments

@philn16
Copy link

philn16 commented Aug 2, 2019

I've noticed a bizzar frequency response from the rrcosfilter. I suspect this is an edge case due to the if/else in the module. The time waveform doesn't look unusual.

import matplotlib.pyplot as plt
import scipy.fftpack as fftpack
from commpy import rrcosfilter
import numpy as np
import scipy

def padded_centered_fft(taps,mintaps=1024,db=True,db_min=-300,fs=1):
	""" returns the fft of the zero padded taps, and centers it """
	if len(taps) < mintaps:
		taps=np.concatenate((taps,np.zeros(mintaps-len(taps))))
	dfreq, fft = fftpack.fftshift(fftpack.fftfreq(len(taps))),fftpack.fftshift(scipy.fft(taps))
	fft_abs=np.abs(fft)
	fft_db = 20*np.log10(fft_abs+max(np.abs(fft))*(10**((db_min-50)/20)) )
	fft_db[np.where(fft_db < db_min)]=db_min
	dfreq*=fs
	return (dfreq, fft_db) if db else (dfreq,fft)

plt.plot(*padded_centered_fft(rrcosfilter(N=400,alpha=0.15,Ts=1,Fs=3.01)[1]),label='3.01')
plt.plot(*padded_centered_fft(rrcosfilter(N=400,alpha=0.15,Ts=1,Fs=3)[1]),label='3')
plt.plot(*padded_centered_fft(rrcosfilter(N=400,alpha=0.15,Ts=1,Fs=2.99)[1]),':',label='2.99')
plt.legend(loc='best')
plt.show()

response

@philn16
Copy link
Author

philn16 commented Aug 2, 2019

here's the rrcosfilter function from the commpy I'm using:

def rrcosfilter(N, alpha, Ts, Fs):
    """
    Generates a root raised cosine (RRC) filter (FIR) impulse response.

    Parameters
    ----------
    N : int
        Length of the filter in samples.

    alpha : float
        Roll off factor (Valid values are [0, 1]).

    Ts : float
        Symbol period in seconds.

    Fs : float
        Sampling Rate in Hz.

    Returns
    ---------

    time_idx : 1-D ndarray of floats
        Array containing the time indices, in seconds, for
        the impulse response.

    h_rrc : 1-D ndarray of floats
        Impulse response of the root raised cosine filter.
    """

    T_delta = 1/float(Fs)
    time_idx = ((np.arange(N)-N/2))*T_delta
    sample_num = np.arange(N)
    h_rrc = np.zeros(N, dtype=float)

    for x in sample_num:
        t = (x-N/2)*T_delta
        if t == 0.0:
            h_rrc[x] = 1.0 - alpha + (4*alpha/np.pi)
        elif alpha != 0 and t == Ts/(4*alpha):
            h_rrc[x] = (alpha/np.sqrt(2))*(((1+2/np.pi)* \
                    (np.sin(np.pi/(4*alpha)))) + ((1-2/np.pi)*(np.cos(np.pi/(4*alpha)))))
        elif alpha != 0 and t == -Ts/(4*alpha):
            h_rrc[x] = (alpha/np.sqrt(2))*(((1+2/np.pi)* \
                    (np.sin(np.pi/(4*alpha)))) + ((1-2/np.pi)*(np.cos(np.pi/(4*alpha)))))
        else:
            h_rrc[x] = (np.sin(np.pi*t*(1-alpha)/Ts) +  \
                    4*alpha*(t/Ts)*np.cos(np.pi*t*(1+alpha)/Ts))/ \
                    (np.pi*t*(1-(4*alpha*t/Ts)*(4*alpha*t/Ts))/Ts)

    return time_idx, h_rrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant