<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function <EOL> import unittest <EOL> import pkg_resources <EOL> import scipy . io <EOL> import numpy as np <EOL> import deltasigma as ds <EOL> from scipy . signal import lti <EOL> class TestSimulateSNR ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> pass <EOL> def test_simulateSNR_1 ( self ) : <EOL> """<STR_LIT>""" <EOL> fname = pkg_resources . resource_filename ( __name__ , <EOL> "<STR_LIT>" ) <EOL> amp_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( - <NUM_LIT:1> , ) ) <EOL> snr_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( - <NUM_LIT:1> , ) ) <EOL> amp_user_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( - <NUM_LIT:1> , ) ) <EOL> snr_user_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( - <NUM_LIT:1> , ) ) <EOL> order = <NUM_LIT:4> <EOL> osr = <NUM_LIT> <EOL> nlev = <NUM_LIT:2> <EOL> f0 = <NUM_LIT> <EOL> Hinf = <NUM_LIT> <EOL> form = '<STR_LIT>' <EOL> ntf = ds . synthesizeNTF ( order , osr , <NUM_LIT:2> , Hinf , f0 ) <EOL> a1 , g1 , b1 , c1 = ds . realizeNTF ( ntf , form ) <EOL> ABCD = ds . stuffABCD ( a1 , g1 , b1 , c1 , form ) <EOL> ABCD_ref = np . array ( [ [ <NUM_LIT:1.> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:1.> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1.> , <NUM_LIT:1.> , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1.> , <NUM_LIT:1.> , - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:0> ] ] ) <EOL> self . assertTrue ( np . allclose ( ABCD , ABCD_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> a2 , g2 , b2 , c2 = ds . mapABCD ( ABCD , form ) <EOL> self . assertTrue ( np . allclose ( a1 , a2 , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( g1 , g2 , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( b1 , b2 , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( c1 , c2 , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> snr , amp = ds . simulateSNR ( ABCD , osr , None , f0 , nlev ) <EOL> self . assertTrue ( np . allclose ( snr , snr_ref , atol = <NUM_LIT:1> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( amp , amp_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> snr2 , amp2 = ds . simulateSNR ( ntf , osr , None , f0 , nlev ) <EOL> self . assertTrue ( np . allclose ( snr2 , snr_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( amp2 , amp_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> amp_user = np . linspace ( - <NUM_LIT:100> , <NUM_LIT:0> , <NUM_LIT:200> ) [ : : <NUM_LIT:10> ] <EOL> snr_user , amp_user = ds . simulateSNR ( lti ( * ntf ) , osr = osr , amp = amp_user , <EOL> f0 = f0 , nlev = nlev ) <EOL> self . assertTrue ( np . allclose ( snr_user , snr_user_ref [ : : <NUM_LIT:10> ] , atol = <NUM_LIT> , <EOL> rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( amp_user , amp_user_ref [ : : <NUM_LIT:10> ] , atol = <NUM_LIT> , <EOL> rtol = <NUM_LIT> ) ) <EOL> def test_simulateSNR_2 ( self ) : <EOL> """<STR_LIT>""" <EOL> fname = pkg_resources . resource_filename ( __name__ , <EOL> "<STR_LIT>" ) <EOL> amp_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( - <NUM_LIT:1> , ) ) <EOL> snr_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( - <NUM_LIT:1> , ) ) <EOL> ABCD_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> order = <NUM_LIT:3> <EOL> osr = <NUM_LIT> <EOL> nlev = <NUM_LIT:2> <EOL> f0 = <NUM_LIT:0.> <EOL> Hinf = <NUM_LIT> <EOL> form = '<STR_LIT>' <EOL> ntf = ds . synthesizeNTF ( order , osr , <NUM_LIT:2> , Hinf , f0 ) <EOL> a1 , g1 , b1 , c1 = ds . realizeNTF ( ntf , form ) <EOL> a1_ref = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> g1_ref = [ <NUM_LIT> ] <EOL> b1_ref = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ] <EOL> c1_ref = [ <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:1.> ] <EOL> self . assertTrue ( np . allclose ( a1 , a1_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( g1 , g1_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( b1 , b1_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( c1 , c1_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> ABCD = ds . stuffABCD ( a1 , g1 , b1 , c1 , form ) <EOL> self . assertTrue ( np . allclose ( ABCD , ABCD_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> snr , amp = ds . simulateSNR ( ABCD , osr , None , f0 , nlev ) <EOL> self . assertTrue ( np . allclose ( snr , snr_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( amp , amp_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> def test_simulateSNR_3 ( self ) : <EOL> """<STR_LIT>""" <EOL> fname = pkg_resources . resource_filename ( __name__ , <EOL> "<STR_LIT>" ) <EOL> amp_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( - <NUM_LIT:1> , ) ) [ <NUM_LIT:0> ] <EOL> snr_ref = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( - <NUM_LIT:1> , ) ) [ <NUM_LIT:0> ] <EOL> ABCD = scipy . io . loadmat ( fname ) [ '<STR_LIT>' ] . reshape ( ( <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> order = <NUM_LIT:3> <EOL> osr = <NUM_LIT> <EOL> nlev = <NUM_LIT:2> <EOL> f0 = <NUM_LIT:0.> <EOL> Hinf = <NUM_LIT> <EOL> form = '<STR_LIT>' <EOL> ntf = ds . synthesizeNTF ( order , osr , <NUM_LIT:2> , Hinf , f0 ) <EOL> snr , amp = ds . simulateSNR ( ABCD , osr , amp_ref , f0 , nlev ) <EOL> self . assertTrue ( np . allclose ( snr , snr_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> self . assertTrue ( np . allclose ( amp , amp_ref , atol = <NUM_LIT> , rtol = <NUM_LIT> ) ) <EOL> def test_simulateSNR_4 ( self ) : <EOL> """<STR_LIT>""" <EOL> SNR_ref = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> AMP_ref = np . array ( [ - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT:50> , - <NUM_LIT> , - <NUM_LIT:30> , - <NUM_LIT:20> , - <NUM_LIT:15> , - <NUM_LIT:10> , - <NUM_LIT:9> , - <NUM_LIT:8> , - <NUM_LIT:7> , <EOL> - <NUM_LIT:6> , - <NUM_LIT:5> , - <NUM_LIT:4> , - <NUM_LIT:3> , - <NUM_LIT:2> , - <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> order = <NUM_LIT:4> <EOL> osr = <NUM_LIT:32> <EOL> M = <NUM_LIT:8> <EOL> NG = - <NUM_LIT:50> <EOL> ING = - <NUM_LIT:10> <EOL> f0 = <NUM_LIT:1.> / <NUM_LIT:16> <EOL> quadrature = <NUM_LIT:1> <EOL> form = '<STR_LIT>' <EOL> nlev = M + <NUM_LIT:1> <EOL> z0 = np . exp ( <NUM_LIT> * <NUM_LIT:2> * np . pi * f0 ) <EOL> bw = <NUM_LIT:1.> / osr <EOL> delta = <NUM_LIT:2> <EOL> FullScale = M <EOL> ntf0 = ds . synthesizeQNTF ( order , osr , f0 , NG , ING ) <EOL> ABCD = ds . realizeQNTF ( ntf0 , form , True ) <EOL> a , b = ds . simulateSNR ( ABCD , osr , None , f0 , nlev ) ; <EOL> assert np . allclose ( a [ <NUM_LIT:6> : ] , SNR_ref , atol = <NUM_LIT:10> , rtol = <NUM_LIT> ) <EOL> assert np . allclose ( b [ <NUM_LIT:5> : ] , AMP_ref , atol = <NUM_LIT:1> ) </s>
