signals

How can i plot the sum of two discrete signal?

醉酒当歌 提交于 2020-01-06 16:21:00
问题 I have a discrete signal x = [ 1 2 3 4 5 6 ] with n = [ -2 -1 0 1 2 3 ] How can i plot y[n] = x[n-1] + x[n-2] + x[n] ? Thanks. 回答1: You can do the following: y = x(1:end-2) + x(2:end-1) + x(3:end); plot(n(3:end), y) 回答2: This looks like a filter... You should consider using the filter function to calculate y : x = [...whatever...]; % Filter coefficients from your difference equation. b = [1 1 1]; a = 1; y = filter(b, a, x); plot(n, y); This will handle initial conditions more appropriately

How To Add Session Variables with Built-In login view

谁说我不能喝 提交于 2020-01-06 06:48:32
问题 I used the built-in login view that django makes but now I don't know how to set sessions when a user logs in. I was thinking of redirecting a user to a new view that would add these session variables but I don't see that as an ideal fix. Another question I have is: Can I use these session variables in my templates? If not, how would I get that data to the templates? Also I am using Django 1.11 with python 2.7. 回答1: I figured out what I needed to do. You need to use signals. Essentially you

how to assign a context to a socket or an epoll event

拜拜、爱过 提交于 2020-01-06 01:09:30
问题 I want to write an event based server using epoll. each client has a distinct request, and the server should respond to them. the server will wait for connections, and when connections are available they're queued for read. data is read from the clients and they'll be queued for write. after processing the data, an appropriate response should be sent to each. all the operations will be asynchronously. the problem is, how can I determine, which response is for which socket when the sockets are

Non-blocking socket accept without spinlock in C [duplicate]

删除回忆录丶 提交于 2020-01-05 03:32:13
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Wake up thread blocked on accept() call I am writing a small server which listening for connections (accepting them and passing them to worker threads) until a custom stop signal is sent. If I use blocking sockets, then my main accept loop cannot break on the custom stop signal being sent. However, I wish to avoid having a busy-wait/spinlock loop with a non-blocking socket. What I want is for my main accept loop

Non-blocking socket accept without spinlock in C [duplicate]

旧巷老猫 提交于 2020-01-05 03:31:14
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Wake up thread blocked on accept() call I am writing a small server which listening for connections (accepting them and passing them to worker threads) until a custom stop signal is sent. If I use blocking sockets, then my main accept loop cannot break on the custom stop signal being sent. However, I wish to avoid having a busy-wait/spinlock loop with a non-blocking socket. What I want is for my main accept loop

C2665: 'QObject::connect' : none of the 3 overloads could convert all the arguments types

こ雲淡風輕ζ 提交于 2020-01-05 03:08:32
问题 I have the following code in main QProcess process; QObject::connect(&process, &QProcess::error, [](QProcess::ProcessError error) { qDebug() << error; }, Qt::QueuedConnection); bool launched = process.startDetached("D:\temp.exe"); and it is generating this error while compiling D:\main.cpp:5: error: C2665: 'QObject::connect' : none of the 3 overloads could convert all the argument types c:\qt\5.3\msvc2013_64\include\qtcore\qobject.h(205): could be 'QMetaObject::Connection QObject::connect

How do you increment a count while using the sleep function?

我与影子孤独终老i 提交于 2020-01-04 06:51:13
问题 Hey guys I seem to be lost. I am supposed to be able to increment a count in a child inside an infinite loop, and to have the count be printed every time the parent sends a signal, which should be every 1 second. I wrote my code but I thought that after using fork, the child and parent processes run at the same time, however this is not the case so I'm not sure how to tackle this problem. Any help would be great 回答1: What you are describing should work in theory. Writing parallel code can be

Posix threads:Signal a thread that is running in while loop

為{幸葍}努か 提交于 2020-01-04 05:26:25
问题 I have a thread that is a very simple: it sends keep-alive packets to a server, then sleeps. I would like my main thread to signal the thread to quit, but whenever I call pthread_kill() it seems to crash my process. I tried to call sigpending() followed by sigismember() at the beginning of my while loop, but I think it is crashing because it doesn't know of any handle to take care of the signal (I was using sigaddset() before the while loop), as follow: void* foo(void* arg) { sigset_t set,

VHDL : Multiple rising_edge detections inside a process block

走远了吗. 提交于 2020-01-04 04:08:14
问题 I'm pretty new to VHDL (and digital circuits in general), and I'm trying to implement a counter of two digits using BCD style blocks. External to this circuit there is going to be buttons, which when pressed, will bump the digit of interest up by one (much like an alarm clock would). This is an asynchronous action, and will occur when in some form of edit mode (externally enforced). The code I have written works fine without the "elsif rising_edge(digitUp1) then" and "elsif rising_edge

Handling segfault signal SIGSEGV need to determine the cause of segfault using siginfo_t

独自空忆成欢 提交于 2020-01-04 02:11:18
问题 I'm making a wrapper for the pthread library that allows each thread to have its own set of non-shared memory. Right now the way c is set up if any thread tries to rwe another threads data, the program segfaults. This is fine, I can catch it with a sighandler and call pthread_exit() and continue on with the program. But not every segfault is going to be the result of a bad rwe. I need to find a way to use the siginfo type to determine if the segfault was bad programming or this error. Any