How to port C Lowpass filter code into Julia
I am having difficulty porting Julius Smith's lowpass filter C code into Julia. In particular, I am having difficulty understanding how this particular C for loop can be executed within Julia.
/* C function implementing the simplest lowpass:
*
* y(n) = x(n) + x(n1)
*
*/
double simplp (double *x, double *y,
int M, double xm1)
{
int n;
y[0] = x[0] + xm1;
for (n=1; n < M ; n++) {
y[n] = x[n] + x[n1];
}
return x[M1];
}
Here is the webpage where the code resides for more context: https://ccrma.stanford.edu/~jos/fp/Definition_Simplest_Low_Pass.html
Thanks, Nakul
See also questions close to this topic

(WDK)unresolved external symbol @_CheckForDebuggerJustMyCode@4 referenced in function _DriverEntry@8
I made my first kerneldriver sample.
I made some modifications to the codes following this site
,but errors occur.
modifications:
1.Right Clicking on solution file and left clicking on properties "Configuration Properties > C/C++ > General > Support Just My Code Debugging" option to no.
2.Right Clicking on solution file and left clicking on properties In project settings, add /JMC to "Configuration Properties" > "C/C++" > "Command line" > "Additional Options"
3.Right Clicking on solution file and left clicking on properties "Platform" >x64
/* hello.c */ #include <wdm.h> #pragma warning(disable: 4100) DRIVER_INITIALIZE DriverEntry; NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) { DbgPrint("Hello, World!\n"); return STATUS_SUCCESS; }
error massage is
/*error LNK2019 unresolved external symbol @__CheckForDebuggerJustMyCode@4 referenced in function _DriverEntry@8 LNK1120 1 unresolved externals */
If you have some solution, please let me know.
pc environment : windows10 pro ,VisualStudio2017,WDKver1803

Call Stack of a Selected frame
I am debugging a segmentation fault from the core file and trying to get as much info as possible. Below is a snippet of my
bt
command.(gdb) bt #0 0x00000000007d4cf1 in alloc_real (vv=0x7f259e9bed20, drop_ssr=false) task_remove.c:2350 #1 0x00000000007d54f8 in ssr_unalloc (vv=0x7f259e9bed20, skip_tree=1 '\001', remove_from_sysmgr=0 '\000') at task_remove.c:2541 #2 0x00000000007e5afb in remove_done (vv=0x7f259e9bed20, status=TE_PASS, multiple_ssr=2) at task_remove.c:7058 #3 0x00000000007ee0f4 in remove_callback (task=0x7f259e9e27d0) at task_remove.c:8790 #4 0x00000000006fe4d5 in proc (arg=0x7f259e9e27d0) at smtproc.c:140 #5 0x00007f25a2cab637 in ?? () #6 0x00007f25a55ed998 in ?? ()
From
bt
I can know that the program failed intask_remove.c:2350
while executing line no 2350 of thealloc_real
function. The code for'alloc_real'
has several other function calls which has passed and hence removed from the stack.My question is, Is there any way/mechanism to get the
bt
offrame 0
, or in other words all the functions called by 'alloc_real
' using gdb. 
Why does sizeof(a) / sizeof(*a) fail to work when moved to a function in C?
#include <stdio.h> int main(void) { int a[3] = {11, 22, 33}; printf("%d\n", sizeof(a) / sizeof(*a)); return 0; }
Look at the above code, in which sizeof(a) / sizeof(*a) can be used to calculate how many elements are included in the array a.
I understand a in sizeof(a) represents a[].
Now I try to create a function called calnum to do that.
#include <stdio.h> int calnum(int *p); int main(void) { int a[] = {11, 22, 33}; printf("%d\n", calnum(a)); return 0; } int calnum(int *p) { int n; n = sizeof(p) / sizeof(*p); return n; }
Output is 2.
When I add more elements to array a, like a[] = {11, 22, 33, 44, 55, 566};
Output is always 2.
Why does sizeof(a) / sizeof(*a) fail to work when moved to a function ?

Julia 1.0 UndefVarError  Scope of Variable
I am moving from Julia 0.7 to 1.0. It seems that Julia's rule for the scope of variables changed from 0.7 to 1.0. For example, I want to run a simple loop like this:
num = 0 for i = 1:5 if i == 3 num = num + 1 end end print(num)
In Julia 0.7 (and in most of other languages), we could expect
num = 1
after the loop. However, it will incurUndefVarError: num not defined
in Julia 1.0. I know that by usinglet
I can do thislet num = 0 for i = 1:5 if i == 3 num = num + 1 end end print(num) end
It will print out 1. But I do want to get the
num = 1
outside the loop and thelet
block. Some answers suggest putting all code in alet
block, but it will incur other problems includingUndefVarError
while testing linebyline. Is there any way instead of usinglet
blocking? Thanks! 
Collapse array of sets to single set in Julia
How do I collapse an array of sets to a single set containing all unique set elements in the following way?
Array_of_sets = Set{String}[Set(["EUR", "GBP", "USD"]), Set(["AUD"])] # do something to Array_of_sets which produces Set{String}(["EUR", "GBP", "USD", "AUD"])
union
,vcat
andunique
do not seem to work in this case. 
Generating a weighted and directed network form adjacency matrix in Julia
I want to generate a weighted and directed network from an adjacency matrix in Julia (v0.7).
So far I've tried:
using LightGraphs using SimpleWeightedGraphs A = rand(100, 100) G = Graph(A)
but I get error:
ERROR: ArgumentError: Adjacency / distance matrices must be symmetric Stacktrace: [1] SimpleGraph{Int64}(::Array{Float64,2}) at /home/user/.julia/packages/LightGraphs/PPsyP/src/SimpleGraphs/simplegraph.jl:78 [2] SimpleGraph(::Array{Float64,2}) at /home/user/.julia/packages/LightGraphs/PPsyP/src/SimpleGraphs/simplegraph.jl:72 [3] toplevel scope at none:0
So far I have only seen the example on the github (https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl) page which generates the weighted graph from and edgelist. However, I would prefer if I could generate the graph directly from an adjacency matrix.

Prolem with lowpass butter filter in Python
I wanted to filter (lowpass) a signal i have, and when it did not work, i started investigating why it wouldn't. I have made a few tests and i am somewhat surprised by the behavior of the butterworth filter. i have defined it like in this post
def apply_filter(data, cutoff, fs, order=6, filter_type="low", analog=False): nyq = 0.5 * fs normalized_cutoff = cutoff / nyq b,a = butter(order, normalized_cutoff, btype=filter_type, analog=analog, output="ba") they = lfilter(b, a, data) return(they)
if i take a 1000 elements long sample, like so
x = np.linspace(0, 2*np.pi, 1000) y = np.sin(x) + 0.3* np.sin(10*x) sampling_frequency = 1/ (x[1] * 1e3) sampling_frequency >> 159.15494309189532 # because i have 1000 thousand points for a "time" going up to 2 pi plt.plot(x, y, x, apply_filter(y, cutoff=1, fs= sampling_frequency)
to which i get
on the other hand, if i do the exact same thing but with a different number of points, say, 10000, i get a wrong result, and i don't quite understand why:
x = np.linspace(0, 2*np.pi, 10000) y = np.sin(x) + 0.3* np.sin(10*x) sampling_frequency = 1/ (x[1] * 1e4) sampling_frequency >> 1591.5494309189535 # because i have 10000 thousand points for a "time" going up to 2 pi plt.plot(x, y, x, apply_filter(y, cutoff=1, fs= sampling_frequency)
and this time, i obtain
which is obviously wrong. Can someone explain why would that happen? things seem to function alright for 1000 points or less...
EDIT:
I have plotted the frequency response of the filter, and the problem appears on these graphs, although i don't know why it does that either.
sampling rate >> 159.1549430918953 b, a = butter(6, 1/(sampling_rate/2)) w, h = freqz(b, a, 8000) plt.subplot(2,1,1) plt.xlim(0, 15) plt.plot(0.5*sampling_rate*w/np.pi, np.abs(h))
to which i get
whereas, if i do
sampling_frequency *= 10 sampling_frequency >> 1591.5494309189535 b, a = butter(6, 1/(sampling_rate/2)) w, h = freqz(b, a, 8000) plt.subplot(2,1,1) plt.xlim(0, 15) plt.plot(0.5*sampling_rate*w/np.pi, np.abs(h))
then i get
I feel like the function butterworth is having some trouble with a high number of points for some reason perhaps?
thanks for your help!

From time domaine to frequency domain
I have a problem in my MATLAB program. I'm trying to find a cutoff frequency to create a low pass filter for compass data. I'm trying to go from the time domain to the frequency domain and find an
Fc
, so I used the FFT but it seems that's it's nor working.This is what i have done:
dataset=xlsread('data.xlsx','Feuil1','A1:A751'); t=1:length(dataset); z=abs(fft(dataset)); subplot(2,2,3) plot(dataset) title('dataNonFiltrer') subplot(2,2,4) plot(z) title('frequenciel')
And i get this wish seems to be not correct:

Setting up a lowpass filter with 50 Hz in R without phase distortion?
I have collected eyetracking data with 500 Hz sampling frequency. I have computed the velocity of the eyemovements and now I would like to apply a 50 Hz low pass filter to the velocity profiles (as have other researchers, for example Jainta, Hoormann, & Jaschinski (2007)).
I am struggeling to set up a 50 Hz lowpass filter in R. I tried using the package signal.
As I understood, when using a Butterworth filter with my sampling frequency of 500 Hz, I would have to use W = 0.2 to achieve a 50 Hz lowpass filter. Is the following correct?
bf < butter(n = 1, w = 0.2, type = "low", plane = "z") y_filtered < filter(bf, y)
However, this will result in a phase distortion as, for example, shown in this post:
How do I run a high pass or low pass filter on data points in R?
Also according to the answers in the linked post, I would have to use W = 0.4 to achieve a 50 Hz lowpass filter when using the function filtfilt to avoid phase distortion. Is that correct?
However, since in the documentations of filtfilt there is "... so this function needs some work yet  and is in the state of the year 2000 version of the Octave code." I would not like to use it if there is another option.
I considered using loess, but are unsure, which span would be equivalent to a 50 Hz filter? According to linked video, span is set to a proportion of the total number of data points. Is this also true in R?
https://www.youtube.com/watch?v=Vf7oJ6z2LCc
What would that mean in my case, how would I need to choose span?
Maybe there a other functions I would better use, of which I am not aware so far...
So, could someone help me with setting up a 50 Hz lowpass filter? Any help would be appreciated.