Compare commits
No commits in common. "03064b235c7b238121659f88ed8774fa98dc450e" and "df11e3423557fd96caa9817a2f141bb33575b9b6" have entirely different histories.
03064b235c
...
df11e34235
5 changed files with 2 additions and 103 deletions
42
fir.c
42
fir.c
|
|
@ -1,42 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define N 5 // Number of taps (filter coefficients)
|
|
||||||
|
|
||||||
// Example filter coefficients (simple low-pass averaging filter)
|
|
||||||
float coeffs[N] = {
|
|
||||||
0.2, 0.2, 0.2, 0.2, 0.2 // Equal weights → moving average filter
|
|
||||||
};
|
|
||||||
|
|
||||||
float buffer[N] = {0}; // Circular buffer to store recent inputs
|
|
||||||
int bufIndex = 0;
|
|
||||||
|
|
||||||
float fir_filter(float input) {
|
|
||||||
buffer[bufIndex] = input;
|
|
||||||
|
|
||||||
float output = 0.0;
|
|
||||||
int index = bufIndex;
|
|
||||||
|
|
||||||
// Apply the convolution (dot product of input buffer and coefficients)
|
|
||||||
for (int i = 0; i < N; ++i) {
|
|
||||||
output += coeffs[i] * buffer[index];
|
|
||||||
if (--index < 0)
|
|
||||||
index = N - 1; // Wrap around circular buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
bufIndex = (bufIndex + 1) % N;
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
float noisy_signal[] = {1, 2, 3, 2,
|
|
||||||
100, 3, 2, 1}; // A spike in the middle (100)
|
|
||||||
int len = sizeof(noisy_signal) / sizeof(float);
|
|
||||||
|
|
||||||
printf("Filtered output:\n");
|
|
||||||
for (int i = 0; i < len; ++i) {
|
|
||||||
float filtered = fir_filter(noisy_signal[i]);
|
|
||||||
printf("%.2f\n", filtered);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
---@meta
|
|
||||||
|
|
||||||
--- Prints a string.
|
|
||||||
---@param str string The string to print.
|
|
||||||
function myprint(str) end
|
|
||||||
|
|
||||||
--- Add two integers
|
|
||||||
---@param a number The first integer
|
|
||||||
---@param b number The second integer
|
|
||||||
---@return number Result (a + b)
|
|
||||||
function c_add(a, b) end
|
|
||||||
|
|
@ -10,37 +10,9 @@ int c_add(lua_State *L) {
|
||||||
return 1; // one return value
|
return 1; // one return value
|
||||||
}
|
}
|
||||||
|
|
||||||
int c_print(lua_State *L) {
|
|
||||||
const char *c = luaL_checkstring(L, 1);
|
|
||||||
printf("%s\n", c);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int luaB_print(lua_State *L) {
|
|
||||||
int n = lua_gettop(L); /* number of arguments */
|
|
||||||
int i;
|
|
||||||
for (i = 1; i <= n; i++) { /* for each argument */
|
|
||||||
size_t l;
|
|
||||||
const char *s = luaL_tolstring(L, i, &l); /* convert it to string */
|
|
||||||
if (i > 1) /* not the first element? */
|
|
||||||
lua_writestring("\t", 1); /* add a tab before it */
|
|
||||||
lua_writestring(s, l); /* print it */
|
|
||||||
lua_pop(L, 1); /* pop result */
|
|
||||||
}
|
|
||||||
lua_writeline();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int luaB_type(lua_State *L) {
|
|
||||||
int t = lua_type(L, 1);
|
|
||||||
luaL_argcheck(L, t != LUA_TNONE, 1, "value expected");
|
|
||||||
lua_pushstring(L, lua_typename(L, t));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
lua_State *L = luaL_newstate();
|
lua_State *L = luaL_newstate();
|
||||||
// luaL_openlibs(L); // Load Lua standard libraries
|
luaL_openlibs(L); // Load Lua standard libraries
|
||||||
|
|
||||||
const lua_Number ver = lua_version(NULL);
|
const lua_Number ver = lua_version(NULL);
|
||||||
|
|
||||||
|
|
@ -49,9 +21,6 @@ int main(void) {
|
||||||
|
|
||||||
// Register the C function as a global Lua function
|
// Register the C function as a global Lua function
|
||||||
lua_register(L, "c_add", c_add);
|
lua_register(L, "c_add", c_add);
|
||||||
lua_register(L, "myprint", c_print);
|
|
||||||
lua_register(L, "print", luaB_print);
|
|
||||||
lua_register(L, "type", luaB_type);
|
|
||||||
|
|
||||||
// Run the Lua script
|
// Run the Lua script
|
||||||
if (luaL_dofile(L, "script.lua") != LUA_OK) {
|
if (luaL_dofile(L, "script.lua") != LUA_OK) {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
local result = c_add(10, 25)
|
local result = c_add(10, 25)
|
||||||
print("Type: ", type(result))
|
|
||||||
print("Result from C function: " .. result)
|
print("Result from C function: " .. result)
|
||||||
|
|
||||||
HereYouCan = {
|
HereYouCan = {
|
||||||
"Execute Arbitrary Lua Code",
|
"Execute Arbitrary Lua Code"
|
||||||
}
|
}
|
||||||
|
|
||||||
print(HereYouCan[1])
|
print(HereYouCan[1])
|
||||||
myprint(HereYouCan[1])
|
|
||||||
myprint("Hello" .. " " .. "World")
|
|
||||||
|
|
|
||||||
14
thread.c
14
thread.c
|
|
@ -1,14 +0,0 @@
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void *worker(void *arg) {
|
|
||||||
printf("Hello from thread\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
pthread_t thread;
|
|
||||||
pthread_create(&thread, NULL, worker, NULL);
|
|
||||||
pthread_join(thread, NULL);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue