Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
HDL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RTSD
HDL
Commits
62d44525
Commit
62d44525
authored
9 months ago
by
Eric Kooistra
Browse files
Options
Downloads
Patches
Plain Diff
Logging layout.
parent
7927866d
Branches
Branches containing commit
No related tags found
1 merge request
!419
Resolve RTSD-265
Pipeline
#91851
passed
9 months ago
Stage: linting
Changes
2
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
applications/lofar2/model/pfb_os/narrowband_noise_generator.ipynb
+48
-39
48 additions, 39 deletions
...ions/lofar2/model/pfb_os/narrowband_noise_generator.ipynb
applications/lofar2/model/pfb_os/up_down_sampling.ipynb
+33
-42
33 additions, 42 deletions
applications/lofar2/model/pfb_os/up_down_sampling.ipynb
with
81 additions
and
81 deletions
applications/lofar2/model/pfb_os/narrowband_noise_generator.ipynb
+
48
−
39
View file @
62d44525
This diff is collapsed.
Click to expand it.
applications/lofar2/model/pfb_os/up_down_sampling.ipynb
+
33
−
42
View file @
62d44525
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
37
,
"execution_count":
1
,
"id": "02689e50",
"id": "02689e50",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
...
@@ -30,19 +30,10 @@
...
@@ -30,19 +30,10 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
38
,
"execution_count":
2
,
"id": "acea4f0a",
"id": "acea4f0a",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"source": [
"# Auto reload module when it is changed\n",
"# Auto reload module when it is changed\n",
"%load_ext autoreload\n",
"%load_ext autoreload\n",
...
@@ -65,7 +56,7 @@
...
@@ -65,7 +56,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 3
9
,
"execution_count": 3,
"id": "55e0fe37",
"id": "55e0fe37",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
...
@@ -100,7 +91,7 @@
...
@@ -100,7 +91,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 4
0
,
"execution_count": 4,
"id": "e08b5ba2",
"id": "e08b5ba2",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -160,7 +151,7 @@
...
@@ -160,7 +151,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
41
,
"execution_count":
5
,
"id": "0a69b385",
"id": "0a69b385",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -201,7 +192,7 @@
...
@@ -201,7 +192,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
42
,
"execution_count":
6
,
"id": "ca83f348",
"id": "ca83f348",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -251,7 +242,7 @@
...
@@ -251,7 +242,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
43
,
"execution_count":
7
,
"id": "5a402a30",
"id": "5a402a30",
"metadata": {
"metadata": {
"scrolled": true
"scrolled": true
...
@@ -290,7 +281,7 @@
...
@@ -290,7 +281,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
44
,
"execution_count":
8
,
"id": "ee8666c6",
"id": "ee8666c6",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -327,7 +318,7 @@
...
@@ -327,7 +318,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
45
,
"execution_count":
9
,
"id": "860828a7",
"id": "860828a7",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -367,7 +358,7 @@
...
@@ -367,7 +358,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
46
,
"execution_count":
10
,
"id": "53d6535f",
"id": "53d6535f",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -403,7 +394,7 @@
...
@@ -403,7 +394,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
47
,
"execution_count":
11
,
"id": "ed8a87a4",
"id": "ed8a87a4",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
@@ -451,7 +442,7 @@
...
@@ -451,7 +442,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
48
,
"execution_count":
12
,
"id": "d085cf51",
"id": "d085cf51",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
...
...
%% Cell type:markdown id:c69a2eb8 tags:
%% Cell type:markdown id:c69a2eb8 tags:
# Try multirate by up and down sampling
# Try multirate by up and down sampling
Author: Eric Kooistra, apr 2024
Author: Eric Kooistra, apr 2024
Purpose:
Purpose:
*
Practise DSP [1].
*
Practise DSP [1].
References:
References:
1.
dsp_study_erko, summary of DSP books
1.
dsp_study_erko, summary of DSP books
%% Cell type:code id:02689e50 tags:
%% Cell type:code id:02689e50 tags:
```
python
```
python
import
numpy
as
np
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
scipy
import
signal
from
scipy
import
signal
```
```
%% Cell type:code id:acea4f0a tags:
%% Cell type:code id:acea4f0a tags:
```
python
```
python
# Auto reload module when it is changed
# Auto reload module when it is changed
%
load_ext
autoreload
%
load_ext
autoreload
%
autoreload
2
%
autoreload
2
# Add rtdsp module path to $PYTHONPATH
# Add rtdsp module path to $PYTHONPATH
import
os
import
os
import
sys
import
sys
module_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
'
../
'
))
module_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
'
../
'
))
if
module_path
not
in
sys
.
path
:
if
module_path
not
in
sys
.
path
:
sys
.
path
.
insert
(
0
,
module_path
)
sys
.
path
.
insert
(
0
,
module_path
)
# Import rtdsp
# Import rtdsp
from
rtdsp.utilities
import
is_even
from
rtdsp.utilities
import
is_even
from
rtdsp.firfilter
import
prototype_fir_low_pass_filter
from
rtdsp.firfilter
import
prototype_fir_low_pass_filter
from
rtdsp.fourier
import
dtft
from
rtdsp.fourier
import
dtft
from
rtdsp.multirate
import
downsample
,
upsample
,
resample
from
rtdsp.multirate
import
downsample
,
upsample
,
resample
from
rtdsp.plotting
import
plot_power_spectrum
from
rtdsp.plotting
import
plot_power_spectrum
```
```
%% Output
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
%% Cell type:code id:55e0fe37 tags:
%% Cell type:code id:55e0fe37 tags:
```
python
```
python
# Samples
# Samples
fs
=
1
# sample rate
fs
=
1
# sample rate
ts
=
1
/
fs
# sample period
ts
=
1
/
fs
# sample period
fNyquist
=
fs
/
2
fNyquist
=
fs
/
2
Nup
=
3
Nup
=
3
Ndown
=
4
Ndown
=
4
Nrate
=
np
.
max
(
np
.
array
([
Nup
,
Ndown
]))
Nrate
=
np
.
max
(
np
.
array
([
Nup
,
Ndown
]))
```
```
%% Cell type:markdown id:8be7a01e tags:
%% Cell type:markdown id:8be7a01e tags:
# 1 Set up
# 1 Set up
%% Cell type:markdown id:a949b9ff tags:
%% Cell type:markdown id:a949b9ff tags:
## 1.1 Waveform generator (WG)
## 1.1 Waveform generator (WG)
%% Cell type:code id:e08b5ba2 tags:
%% Cell type:code id:e08b5ba2 tags:
```
python
```
python
# Choose freq < fNyquist / Nrate
# Choose freq < fNyquist / Nrate
freq
=
0.3
*
fNyquist
/
Nrate
freq
=
0.3
*
fNyquist
/
Nrate
phase
=
np
.
pi
/
3
phase
=
np
.
pi
/
3
# Time
# Time
Nperiods
=
3
Nperiods
=
3
period
=
1
/
freq
period
=
1
/
freq
Nsim
=
int
(
Nperiods
*
period
/
ts
)
Nsim
=
int
(
Nperiods
*
period
/
ts
)
print
(
str
(
Nsim
))
print
(
str
(
Nsim
))
tWg
=
np
.
arange
(
0
,
Nsim
)
*
ts
tWg
=
np
.
arange
(
0
,
Nsim
)
*
ts
# Sinus signal
# Sinus signal
wgData
=
np
.
sin
(
2
*
np
.
pi
*
freq
*
tWg
+
phase
)
wgData
=
np
.
sin
(
2
*
np
.
pi
*
freq
*
tWg
+
phase
)
# Chirp signal
# Chirp signal
fstart
=
freq
*
1.0
fstart
=
freq
*
1.0
fend
=
freq
*
2.0
fend
=
freq
*
2.0
tend
=
(
Nsim
-
1
)
*
ts
tend
=
(
Nsim
-
1
)
*
ts
# wgData = signal.chirp(tWg, f0=fstart, f1=fend, t1=tend, method='linear', phi=phase)
# wgData = signal.chirp(tWg, f0=fstart, f1=fend, t1=tend, method='linear', phi=phase)
plt
.
plot
(
tWg
,
wgData
,
'
r-
'
,
tWg
,
wgData
,
'
r*
'
)
plt
.
plot
(
tWg
,
wgData
,
'
r-
'
,
tWg
,
wgData
,
'
r*
'
)
plt
.
title
(
'
WG data
'
)
plt
.
title
(
'
WG data
'
)
plt
.
xlabel
(
'
t [ts =
'
+
str
(
ts
)
+
'
]
'
)
plt
.
xlabel
(
'
t [ts =
'
+
str
(
ts
)
+
'
]
'
)
plt
.
ylabel
(
'
voltage
'
)
plt
.
ylabel
(
'
voltage
'
)
plt
.
grid
(
True
)
plt
.
grid
(
True
)
```
```
%% Output
%% Output
80
80
%% Cell type:markdown id:15bf6804 tags:
%% Cell type:markdown id:15bf6804 tags:
## 1.2 Prototype FIR low pass filter
## 1.2 Prototype FIR low pass filter
%% Cell type:code id:0a69b385 tags:
%% Cell type:code id:0a69b385 tags:
```
python
```
python
# Specifications
# Specifications
Ntaps
=
16
Ntaps
=
16
Ncoefs
=
Nup
*
Ntaps
Ncoefs
=
Nup
*
Ntaps
if
is_even
(
Ncoefs
):
if
is_even
(
Ncoefs
):
Ncoefs
-=
1
# make odd to have integer groupDelay
Ncoefs
-=
1
# make odd to have integer groupDelay
hpFactor
=
0.9
hpFactor
=
0.9
transitionFactor
=
0.4
transitionFactor
=
0.4
stopRippleFactor
=
1000
stopRippleFactor
=
1000
kaiserBeta
=
1
kaiserBeta
=
1
hPrototype
=
prototype_fir_low_pass_filter
(
'
firls
'
,
hPrototype
=
prototype_fir_low_pass_filter
(
'
firls
'
,
Nup
,
Ntaps
,
Ncoefs
,
hpFactor
,
transitionFactor
,
stopRippleFactor
,
kaiserBeta
)
Nup
,
Ntaps
,
Ncoefs
,
hpFactor
,
transitionFactor
,
stopRippleFactor
,
kaiserBeta
)
```
```
%% Output
%% Output
> design_fir_low_pass_filter():
> design_fir_low_pass_filter():
. Method = firls
. Method = firls
. Q = 1.000000
. Q = 1.000000
. fpass = 0.150000
. fpass = 0.150000
. fstop = 0.210000
. fstop = 0.210000
. lpBW = 0.360000
. lpBW = 0.360000
. transistionBW = 0.060000
. transistionBW = 0.060000
. fNyquist = 0.500000
. fNyquist = 0.500000
. fs = 1.000000
. fs = 1.000000
. Ncoefs = 47
. Ncoefs = 47
. DC sum = 1.000000
. DC sum = 1.000000
. Symmetrical coefs = True
. Symmetrical coefs = True
%% Cell type:code id:ca83f348 tags:
%% Cell type:code id:ca83f348 tags:
```
python
```
python
# Plot impulse response
# Plot impulse response
plt
.
figure
(
1
)
plt
.
figure
(
1
)
plt
.
plot
(
hPrototype
)
plt
.
plot
(
hPrototype
)
plt
.
title
(
'
Impulse response
'
)
plt
.
title
(
'
Impulse response
'
)
plt
.
grid
(
True
)
plt
.
grid
(
True
)
# Plot transfer function
# Plot transfer function
plt
.
figure
(
2
)
plt
.
figure
(
2
)
fLim
=
None
# (-2, 2)
fLim
=
None
# (-2, 2)
dbLim
=
(
-
150
,
5
)
dbLim
=
(
-
150
,
5
)
h
,
f
,
HF
=
dtft
(
hPrototype
)
h
,
f
,
HF
=
dtft
(
hPrototype
)
plot_power_spectrum
(
f
,
HF
,
'
g
'
,
fs
,
fLim
,
dbLim
)
plot_power_spectrum
(
f
,
HF
,
'
g
'
,
fs
,
fLim
,
dbLim
)
```
```
%% Output
%% Output
%% Cell type:markdown id:acca4f19 tags:
%% Cell type:markdown id:acca4f19 tags:
# 2 Upsampling
# 2 Upsampling
%% Cell type:code id:5a402a30 tags:
%% Cell type:code id:5a402a30 tags:
```
python
```
python
# Adjust output time axis for group delay to align output with input in plot
# Adjust output time axis for group delay to align output with input in plot
groupDelay
=
(
Ncoefs
-
1
)
/
2
groupDelay
=
(
Ncoefs
-
1
)
/
2
print
(
'
Ncoefs =
'
+
str
(
len
(
hPrototype
)))
print
(
'
Ncoefs =
'
+
str
(
len
(
hPrototype
)))
print
(
'
groupDelay =
'
+
str
(
groupDelay
/
Nup
)
+
'
input samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
/
Nup
)
+
'
input samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
)
+
'
interpolated samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
)
+
'
interpolated samples
'
)
tsUp
=
ts
/
Nup
tsUp
=
ts
/
Nup
tUp
=
(
np
.
arange
(
0
,
Nsim
*
Nup
)
-
groupDelay
)
*
tsUp
tUp
=
(
np
.
arange
(
0
,
Nsim
*
Nup
)
-
groupDelay
)
*
tsUp
coefs
=
hPrototype
*
Nup
coefs
=
hPrototype
*
Nup
upsampledData
=
upsample
(
wgData
,
Nup
,
coefs
,
verify
=
True
)
upsampledData
=
upsample
(
wgData
,
Nup
,
coefs
,
verify
=
True
)
```
```
%% Output
%% Output
Ncoefs = 47
Ncoefs = 47
groupDelay = 7.666666666666667 input samples
groupDelay = 7.666666666666667 input samples
groupDelay = 23.0 interpolated samples
groupDelay = 23.0 interpolated samples
> Verify upsample():
> Verify upsample():
. PASSED: correct upsample result
. PASSED: correct upsample result
> Log upsample():
> Log upsample():
. Nup = 3
. Nup = 3
. Nx = 80
. Nx = 80
. len(y) = 240
. len(y) = 240
%% Cell type:code id:ee8666c6 tags:
%% Cell type:code id:ee8666c6 tags:
```
python
```
python
# First plot up, then wg, to show wg samples as well
# First plot up, then wg, to show wg samples as well
plt
.
plot
(
tUp
,
upsampledData
,
'
b-
'
,
tUp
,
upsampledData
,
'
b*
'
)
plt
.
plot
(
tUp
,
upsampledData
,
'
b-
'
,
tUp
,
upsampledData
,
'
b*
'
)
plt
.
plot
(
tWg
,
wgData
,
'
r-
'
,
tWg
,
wgData
,
'
r*
'
)
plt
.
plot
(
tWg
,
wgData
,
'
r-
'
,
tWg
,
wgData
,
'
r*
'
)
plt
.
title
(
'
Upsampled data (Nup = %d)
'
%
Nup
)
plt
.
title
(
'
Upsampled data (Nup = %d)
'
%
Nup
)
plt
.
xlabel
(
'
t [ts =
'
+
str
(
ts
)
+
'
]
'
)
plt
.
xlabel
(
'
t [ts =
'
+
str
(
ts
)
+
'
]
'
)
plt
.
ylabel
(
'
voltage
'
)
plt
.
ylabel
(
'
voltage
'
)
plt
.
xlim
([
18
,
22
])
plt
.
xlim
([
18
,
22
])
plt
.
legend
([
'
up
'
,
''
,
'
wg
'
,
''
])
plt
.
legend
([
'
up
'
,
''
,
'
wg
'
,
''
])
plt
.
grid
(
True
)
plt
.
grid
(
True
)
```
```
%% Output
%% Output
%% Cell type:markdown id:854dbd8d tags:
%% Cell type:markdown id:854dbd8d tags:
# 3 Downsampling
# 3 Downsampling
%% Cell type:code id:860828a7 tags:
%% Cell type:code id:860828a7 tags:
```
python
```
python
# Adjust output time axis for group delay to align output with input in plot
# Adjust output time axis for group delay to align output with input in plot
groupDelay
=
(
Ncoefs
-
1
)
/
2
groupDelay
=
(
Ncoefs
-
1
)
/
2
print
(
'
Ncoefs =
'
+
str
(
len
(
hPrototype
)))
print
(
'
Ncoefs =
'
+
str
(
len
(
hPrototype
)))
print
(
'
groupDelay =
'
+
str
(
groupDelay
)
+
'
input samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
)
+
'
input samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
/
Ndown
)
+
'
downsampled samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
/
Ndown
)
+
'
downsampled samples
'
)
tsDown
=
ts
*
Ndown
tsDown
=
ts
*
Ndown
Dsim
=
1
+
(
Nsim
-
1
)
//
Ndown
Dsim
=
1
+
(
Nsim
-
1
)
//
Ndown
tDown
=
(
np
.
arange
(
0
,
Dsim
)
*
tsDown
)
-
groupDelay
*
ts
tDown
=
(
np
.
arange
(
0
,
Dsim
)
*
tsDown
)
-
groupDelay
*
ts
coefs
=
hPrototype
coefs
=
hPrototype
downsampledData
=
downsample
(
wgData
,
Ndown
,
coefs
,
verify
=
True
)
downsampledData
=
downsample
(
wgData
,
Ndown
,
coefs
,
verify
=
True
)
```
```
%% Output
%% Output
Ncoefs = 47
Ncoefs = 47
groupDelay = 23.0 input samples
groupDelay = 23.0 input samples
groupDelay = 5.75 downsampled samples
groupDelay = 5.75 downsampled samples
> Verify downsample():
> Verify downsample():
. PASSED: correct downsample result
. PASSED: correct downsample result
> Log downsample():
> Log downsample():
. len(x) = 80
. len(x) = 80
. Ndown = 4
. Ndown = 4
. Nx = 77
. Nx = 77
. Nxp = 20
. Nxp = 20
. len(y) = 20
. len(y) = 20
%% Cell type:code id:53d6535f tags:
%% Cell type:code id:53d6535f tags:
```
python
```
python
plt
.
plot
(
tWg
,
wgData
,
'
r-
'
,
tWg
,
wgData
,
'
r*
'
)
plt
.
plot
(
tWg
,
wgData
,
'
r-
'
,
tWg
,
wgData
,
'
r*
'
)
plt
.
plot
(
tDown
,
downsampledData
,
'
b-
'
,
tDown
,
downsampledData
,
'
b*
'
)
plt
.
plot
(
tDown
,
downsampledData
,
'
b-
'
,
tDown
,
downsampledData
,
'
b*
'
)
plt
.
title
(
'
Downsampled data (Ndown = %d)
'
%
Ndown
)
plt
.
title
(
'
Downsampled data (Ndown = %d)
'
%
Ndown
)
plt
.
xlabel
(
'
t [ts =
'
+
str
(
ts
)
+
'
]
'
)
plt
.
xlabel
(
'
t [ts =
'
+
str
(
ts
)
+
'
]
'
)
plt
.
ylabel
(
'
voltage
'
)
plt
.
ylabel
(
'
voltage
'
)
#plt.xlim([55, 65])
#plt.xlim([55, 65])
plt
.
legend
([
'
wg
'
,
''
,
'
down
'
,
''
])
plt
.
legend
([
'
wg
'
,
''
,
'
down
'
,
''
])
plt
.
grid
(
True
)
plt
.
grid
(
True
)
```
```
%% Output
%% Output
%% Cell type:markdown id:b13c9442 tags:
%% Cell type:markdown id:b13c9442 tags:
# 4 Resampling
# 4 Resampling
%% Cell type:code id:ed8a87a4 tags:
%% Cell type:code id:ed8a87a4 tags:
```
python
```
python
# Adjust output time axis for group delay to align output with input in plot
# Adjust output time axis for group delay to align output with input in plot
groupDelay
=
(
Ncoefs
-
1
)
/
2
groupDelay
=
(
Ncoefs
-
1
)
/
2
print
(
'
Ncoefs =
'
+
str
(
len
(
hPrototype
)))
print
(
'
Ncoefs =
'
+
str
(
len
(
hPrototype
)))
print
(
'
groupDelay =
'
+
str
(
groupDelay
/
Nup
)
+
'
input samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
/
Nup
)
+
'
input samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
)
+
'
interpolated samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
)
+
'
interpolated samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
/
Ndown
)
+
'
resampled samples
'
)
print
(
'
groupDelay =
'
+
str
(
groupDelay
/
Ndown
)
+
'
resampled samples
'
)
tsUp
=
ts
/
Nup
tsUp
=
ts
/
Nup
tsDown
=
tsUp
*
Ndown
tsDown
=
tsUp
*
Ndown
Dsim
=
1
+
(
Nsim
*
Nup
-
1
)
//
Ndown
Dsim
=
1
+
(
Nsim
*
Nup
-
1
)
//
Ndown
tResample
=
(
np
.
arange
(
0
,
Dsim
)
*
tsDown
)
-
groupDelay
*
tsUp
tResample
=
(
np
.
arange
(
0
,
Dsim
)
*
tsDown
)
-
groupDelay
*
tsUp
coefs
=
hPrototype
*
Nup
coefs
=
hPrototype
*
Nup
resampledData
=
resample
(
wgData
,
Nup
,
Ndown
,
coefs
,
verify
=
True
)
resampledData
=
resample
(
wgData
,
Nup
,
Ndown
,
coefs
,
verify
=
True
)
```
```
%% Output
%% Output
Ncoefs = 47
Ncoefs = 47
groupDelay = 7.666666666666667 input samples
groupDelay = 7.666666666666667 input samples
groupDelay = 23.0 interpolated samples
groupDelay = 23.0 interpolated samples
groupDelay = 5.75 resampled samples
groupDelay = 5.75 resampled samples
> Log upsample():
> Log upsample():
. Nup = 3
. Nup = 3
. Nx = 80
. Nx = 80
. len(y) = 240
. len(y) = 240
> Verify resample():
> Verify resample():
. PASSED: correct resample result
. PASSED: correct resample result
> Log resample():
> Log resample():
. len(x) = 80
. len(x) = 80
. Nx = 80
. Nx = 80
. len(v) = 240
. len(v) = 240
. Ny = 237
. Ny = 237
. Nyp = 60
. Nyp = 60
. len(y) = 60
. len(y) = 60
%% Cell type:code id:d085cf51 tags:
%% Cell type:code id:d085cf51 tags:
```
python
```
python
plt
.
plot
(
tWg
,
wgData
,
'
r-
'
,
tWg
,
wgData
,
'
r*
'
)
plt
.
plot
(
tWg
,
wgData
,
'
r-
'
,
tWg
,
wgData
,
'
r*
'
)
plt
.
plot
(
tResample
,
resampledData
,
'
b-
'
,
tResample
,
resampledData
,
'
b*
'
)
plt
.
plot
(
tResample
,
resampledData
,
'
b-
'
,
tResample
,
resampledData
,
'
b*
'
)
plt
.
title
(
'
Resampled data (Nup / Ndown = %d / %d)
'
%
(
Nup
,
Ndown
))
plt
.
title
(
'
Resampled data (Nup / Ndown = %d / %d)
'
%
(
Nup
,
Ndown
))
plt
.
xlabel
(
'
t [ts =
'
+
str
(
ts
)
+
'
]
'
)
plt
.
xlabel
(
'
t [ts =
'
+
str
(
ts
)
+
'
]
'
)
plt
.
ylabel
(
'
voltage
'
)
plt
.
ylabel
(
'
voltage
'
)
#plt.xlim([55, 65])
#plt.xlim([55, 65])
plt
.
xlim
([
-
5
,
15
])
plt
.
xlim
([
-
5
,
15
])
plt
.
xlim
([
-
5
,
25
])
plt
.
xlim
([
-
5
,
25
])
plt
.
legend
([
'
wg
'
,
''
,
'
resampled
'
,
''
])
plt
.
legend
([
'
wg
'
,
''
,
'
resampled
'
,
''
])
plt
.
grid
(
True
)
plt
.
grid
(
True
)
```
```
%% Output
%% Output
%% Cell type:code id:b4a95b55 tags:
%% Cell type:code id:b4a95b55 tags:
```
python
```
python
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment