@@ -41,7 +41,7 @@ def PlotExampleSpectrum(ntf, M=1, osr=64, f0=0, quadrature=False):
4141
4242 **Parameters:**
4343
44- ntf : scipy 'lti ' object, tuple or ndarray
44+ ntf : scipy 'dlti ' object, tuple or ndarray
4545 The first argument may be one of the various supported
4646 representations for a (SISO) transfer function or an
4747 ABCD matrix. See :func:`evalTF` for a more detailed
@@ -79,66 +79,109 @@ def PlotExampleSpectrum(ntf, M=1, osr=64, f0=0, quadrature=False):
7979 """
8080 f1 , f2 = ds_f1f2 (osr , f0 , quadrature )
8181 delta = 2
82- Amp = undbv (- 3 ) # Test tone amplitude, relative to full-scale.
82+ Amp = undbv (- 3 ) # Test tone amplitude, relative to full-scale.
8383 # f below is the test tone frequency offset from f0, relative to bw.
8484 # (It will be adjusted to be an fft bin)
8585 f = 0.3
8686 N = 2 ** 12
87- f1_bin = int (np .round (f1 * N ))
88- f2_bin = int (np .round (f2 * N ))
89- fin = round (((1 - f )/ 2 * f1 + (f + 1 )/ 2 * f2 ) * N )
87+ f1_bin = int (np .round (f1 * N ))
88+ f2_bin = int (np .round (f2 * N ))
89+ fin = round (((1 - f ) / 2 * f1 + (f + 1 ) / 2 * f2 ) * N )
9090 if not quadrature :
9191 t = np .arange (0 , N ).reshape ((1 , - 1 ))
92- u = Amp * M * np .cos ((2 * np .pi / N ) * fin * t )
93- v , _ , xmax , y = simulateDSM (u , ntf , M + 1 )
92+ u = Amp * M * np .cos ((2 * np .pi / N ) * fin * t )
93+ v , _ , xmax , y = simulateDSM (u , ntf , M + 1 )
9494 else :
9595 t = np .arange (0 , N ).reshape ((1 , - 1 ))
96- u = Amp * M * np .exp ((2j * np .pi / N ) * fin * t )
97- v , _ , xmax , y = simulateQDSM (u , ntf , M + 1 )
96+ u = Amp * M * np .exp ((2j * np .pi / N ) * fin * t )
97+ v , _ , xmax , y = simulateQDSM (u , ntf , M + 1 )
9898 window = ds_hann (N )
99- NBW = 1.5 / N
100- spec0 = fft (v * window )/ ( M * N / 4 )
99+ NBW = 1.5 / N
100+ spec0 = fft (v * window ) / ( M * N / 4 )
101101 if not quadrature :
102- freq = np .linspace (0 , 0.5 , int (N / 2 ) + 1 )
103- plt .plot (freq , dbv (spec0 [:int (N / 2 ) + 1 ]), 'c' , linewidth = 1 )
104- #plt.hold(True)
105- spec_smoothed = circ_smooth (np .abs (spec0 )** 2. , 16 )
106- plt .plot (freq , dbp (spec_smoothed [:int (N / 2 ) + 1 ]), 'b' , linewidth = 3 )
107- Snn = np .abs (evalTF (ntf , np .exp (2j * np .pi * freq )))** 2 * 2 / 12 * (delta / M )** 2
108- plt .plot (freq , dbp (Snn * NBW ), 'm' , linewidth = 1 )
109- snr = calculateSNR (spec0 [f1_bin :f2_bin + 1 ], fin - f1_bin )
110- msg = 'SQNR = %.1fdB\n @ A = %.1fdBFS & osr = %.0f\n ' % \
111- (snr , dbv (spec0 [fin ]), osr )
102+ freq = np .linspace (0 , 0.5 , int (N / 2 ) + 1 )
103+ plt .plot (freq , dbv (spec0 [: int (N / 2 ) + 1 ]), "c" , linewidth = 1 )
104+ # plt.hold(True)
105+ spec_smoothed = circ_smooth (np .abs (spec0 ) ** 2.0 , 16 )
106+ plt .plot (freq , dbp (spec_smoothed [: int (N / 2 ) + 1 ]), "b" , linewidth = 3 )
107+ Snn = (
108+ np .abs (evalTF (ntf , np .exp (2j * np .pi * freq ))) ** 2
109+ * 2
110+ / 12
111+ * (delta / M ) ** 2
112+ )
113+ plt .plot (freq , dbp (Snn * NBW ), "m" , linewidth = 1 )
114+ snr = calculateSNR (spec0 [f1_bin : f2_bin + 1 ], fin - f1_bin )
115+ msg = "SQNR = %.1fdB\n @ A = %.1fdBFS & osr = %.0f\n " % (
116+ snr ,
117+ dbv (spec0 [fin ]),
118+ osr ,
119+ )
112120 if f0 < 0.25 :
113- plt .text (f0 + 1 / osr , - 15 , msg , horizontalalignment = 'left' ,
114- verticalalignment = 'center' )
121+ plt .text (
122+ f0 + 1 / osr ,
123+ - 15 ,
124+ msg ,
125+ horizontalalignment = "left" ,
126+ verticalalignment = "center" ,
127+ )
115128 else :
116- plt .text (f0 - 1 / osr , - 15 , msg , horizontalalignment = 'right' ,
117- verticalalignment = 'center' )
118- plt .text (0.5 , - 135 , 'NBW = %.1e ' % NBW , horizontalalignment = 'right' ,
119- verticalalignment = 'bottom' )
120- figureMagic ((0 , 0.5 ), 1. / 16 , None , (- 140 , 0 ), 10 , None )
129+ plt .text (
130+ f0 - 1 / osr ,
131+ - 15 ,
132+ msg ,
133+ horizontalalignment = "right" ,
134+ verticalalignment = "center" ,
135+ )
136+ plt .text (
137+ 0.5 ,
138+ - 135 ,
139+ "NBW = %.1e " % NBW ,
140+ horizontalalignment = "right" ,
141+ verticalalignment = "bottom" ,
142+ )
143+ figureMagic ((0 , 0.5 ), 1.0 / 16 , None , (- 140 , 0 ), 10 , None )
121144 else :
122145 spec0 = fftshift (spec0 / 2 )
123146 freq = np .linspace (- 0.5 , 0.5 , N + 1 )
124147 freq = freq [:- 1 ]
125- plt .plot (freq , dbv (spec0 ), 'c' , linewidth = 1 )
126- #plt.hold(True)
127- spec_smoothed = circ_smooth (abs (spec0 )** 2 , 16 )
128- plt .plot (freq , dbp (spec_smoothed ), 'b' , linewidth = 3 )
129- Snn = abs (evalTF (ntf , np .exp (2j * np .pi * freq ))) ** 2 * 2 / 12 * (delta / M ) ** 2
130- plt .plot (freq , dbp (Snn * NBW ), 'm' , linewidth = 1 )
131- snr = calculateSNR (spec0 [N // 2 + f1_bin :N // 2 + f2_bin + 1 ], fin - f1_bin )
132- msg = 'SQNR = %.1fdB\n @ A = %.1fdBFS & osr = %.0f' % \
133- (snr , dbv (spec0 [N // 2 + fin ]), osr )
134- if f0 >= 0 :
135- plt .text (f0 - 0.05 , - 15 , msg , horizontalalignment = 'right' ,
136- verticalalignment = 'bottom' )
148+ plt .plot (freq , dbv (spec0 ), "c" , linewidth = 1 )
149+ # plt.hold(True)
150+ spec_smoothed = circ_smooth (abs (spec0 ) ** 2 , 16 )
151+ plt .plot (freq , dbp (spec_smoothed ), "b" , linewidth = 3 )
152+ Snn = (
153+ abs (evalTF (ntf , np .exp (2j * np .pi * freq ))) ** 2 * 2 / 12 * (delta / M ) ** 2
154+ )
155+ plt .plot (freq , dbp (Snn * NBW ), "m" , linewidth = 1 )
156+ snr = calculateSNR (spec0 [N // 2 + f1_bin : N // 2 + f2_bin + 1 ], fin - f1_bin )
157+ msg = "SQNR = %.1fdB\n @ A = %.1fdBFS & osr = %.0f" % (
158+ snr ,
159+ dbv (spec0 [N // 2 + fin ]),
160+ osr ,
161+ )
162+ if f0 >= 0 :
163+ plt .text (
164+ f0 - 0.05 ,
165+ - 15 ,
166+ msg ,
167+ horizontalalignment = "right" ,
168+ verticalalignment = "bottom" ,
169+ )
137170 else :
138- plt .text (f0 + 0.05 , - 15 , msg , horizontalalignment = 'left' ,
139- verticalalignment = 'bottom' )
140- plt .text (- 0.5 , - 135 , ' NBW = %.1e' % NBW , horizontalalignment = 'left' ,
141- verticalalignment = 'bottom' )
171+ plt .text (
172+ f0 + 0.05 ,
173+ - 15 ,
174+ msg ,
175+ horizontalalignment = "left" ,
176+ verticalalignment = "bottom" ,
177+ )
178+ plt .text (
179+ - 0.5 ,
180+ - 135 ,
181+ " NBW = %.1e" % NBW ,
182+ horizontalalignment = "left" ,
183+ verticalalignment = "bottom" ,
184+ )
142185 figureMagic ((- 0.5 , 0.5 ), 0.125 , None , (- 140 , 0 ), 10 , None )
143- plt .xlabel (' frequency' )
186+ plt .xlabel (" frequency" )
144187 return
0 commit comments