Compare commits

...

4 Commits

Author SHA1 Message Date
Patrick Hangl
1ada8f68ed Neues FIR File angelegt 2025-10-24 12:30:58 +02:00
Patrick Hangl
ba01e9c2a4 Requirements angelegt 2025-09-23 17:01:08 +02:00
Patrick Hangl
234b4bff4c Gitignore angelegt 2025-09-22 17:06:18 +02:00
Patrick Hangl
d21445f5fa Ordnerstruktur angelegt 2025-09-22 17:05:55 +02:00
5 changed files with 122 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/.venv

107
FIR_phangl.ipynb Normal file
View File

@@ -0,0 +1,107 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9c3a0b4a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
]
},
{
"data": {
"text/plain": [
"[0, 0, 0, 0, 0, 0, 0, 0, 0]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# FIR Filter anlegen\n",
"\n",
"from scipy import signal\n",
"from scipy.fft import fft, fftfreq\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from ipywidgets import interact\n",
"\n",
"\n",
"def fir_filter(taps, input): # taps, input sind 1d Eingabelisten mit Koeffizienten und Samples\n",
" fir=[] # Ausgabeliste anlegen\n",
" for j in range(0, len(input) - len(taps)): # Erste Samples (Koeffizientenzahl) zählen nicht zur Filterantwort\n",
" fir_i=0\n",
" for i in range (len(taps)): # Durch Koeffizienten durchiterieren\n",
" taps_i = taps[i] # taps_i ist Laufvariable\n",
" fir_i += taps_i*input[j+i] # fir_i ist Laufvariable für Filterergebnis - jeweiliger Koeffizient wird mit dem i-ten Input-Sample der reduzierten Liste j multipliziert\n",
" fir.append(fir_i) # hänge Ergebnis an Ergebnisliste an\n",
" return fir\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3f78fe4f",
"metadata": {},
"outputs": [],
"source": [
"# Chirp Generator\n",
"\n",
"n=3000 # number of samples to use for the chirp\n",
"fs=20000 # The sampling rate for the chrip\n",
"f0=100# the start frequency in Hz for the chirp\n",
"f1=1000 # the stop frequency of the chirp\n",
"t1=n/fs # the total length of the chirp in s\n",
"\n",
"t_chrip = np.linspace(0, t1, n)\n",
"# generate a chrip and scale to int16 (1 bit for sign)\n",
"y_chrip = np.round(signal.chirp(t_chrip, f0=f0, f1=f1, t1=t1, method='linear')*(2**15-1)).astype(int)\n",
"cutsamps = 45\n",
"y_chrip = y_chrip[cutsamps:]\n",
"t_chrip = t_chrip[cutsamps:]\n",
"\n",
"# Generate an array were the data is present in an interleaved format with the inverted signal \n",
"y_chrip_interleaved = np.empty((2*y_chrip.size), dtype=y_chrip.dtype)pa\n",
"y_chrip_interleaved[0::2] = y_chrip\n",
"y_chrip_interleaved[1::2] = -1*y_chrip[::-1]\n",
"\n",
"file_str= f\"#define CHIRP_DATA_SAMPLE_RATE {int(fs)}\\n\"\\\n",
" \"#define CHIRP_DATA_LEN\"f\" {y_chrip.size}\" \"\\n\"\\\n",
" \"#define CHIRP_DATA_INTERLEAVED_LEN\"f\" {y_chrip_interleaved.size}\" \"\\n\"\\\n",
" \"#define CHIRP_DATA {\" + \",\".join(y_chrip.astype(str)) +\"}\\n\"\\\n",
" \"#define CHIRP_DATA_INTERLEAVED_INVERTED {\" + \",\".join(y_chrip_interleaved.astype(str)) +\"}\" \"\\n\"\n",
"\n",
"with open(\"pcm_chirp/include/chirp_data.h\", \"w\") as f:\n",
" f.write(file_str)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
#define NUMTAPS 62
#define COEFFICIENTS {139,145,159,182,214,255,304,361,425,497,575,659,747,840,935,1033,1131,1229,1325,1420,1511,1597,1678,1752,1820,1879,1929,1970,2002,2023,2033,2033,2023,2002,1970,1929,1879,1820,1752,1678,1597,1511,1420,1325,1229,1131,1033,935,840,747,659,575,497,425,361,304,255,214,182,159,145,139}

7
requirements.txt Normal file
View File

@@ -0,0 +1,7 @@
numpy
matplotlib
soundfile
scipy
ipywidgets
numba
ipympl