On 3 Apr., 15:15, "Rune Allnor" <all...@tele.ntnu.no> wrote:> On 3 Apr, 14:17, "Andor" <andor.bari...@gmail.com> wrote: > > > On 3 Apr., 13:48, "Rune Allnor" <all...@tele.ntnu.no> wrote: > > > > If it's not there you can't filter it out. Your replies are getting > > > > more mysterious as we go along. > > > > C'mon, Andor. I might expect these sorts of objections from a 1st > > > semester student, but from you? > > > I have no idea what you are talking about. > > I understand that now. > > > > Ok, since it is you, I'll show you by spoon-feeding: > > > Mmmmh. > > > [snip analysis of ramp and ramp + cos] > > > > After you run this script, the k=6 coefficient in the > > > ramp-only spectrum (plotted in blue) has a magnitude > > > on the order of 440 or so, while the ramp + cosine > > > coefficient, plotted in red, has a magnitude of 730. > > > That's very nice. It doesn't have the least to do with our discussion, > > though. > > It has everything to do with this discussion. The OP wanted to > filter his data, which are modeled as a general trend like > the ramp with a cosine superimposed, to extract the cosine.That's also possible.> The excercise showed that you can't extract the cosine > model term by this approach.Of course you can. To filter out a n-th degree polynomial trend, just use a filter with an (n+1)-th order zero at zero. For example, the linear trend can be removed using a second order difference filter. However, we (or rather you) are again digreessing. To cut this short, all I did was to dispute your claim (made in the first post that I replied to) "The stock market data don't comply with the assumtions about data the FIR filter techniques is based on." which is quite clearly wrong, no matter how many FFTs you throw around you. Stock market or not, sequences of numbers can always be filtered with FIRs, and the results are always the same. Regards, Andor
Online · Live + on demand
February 9-11, 2027
Price goes up Jan 1: register now to lock in today's rate
Register Now →
FIR Bandpass filtering (C code)
Started by ●March 31, 2007
Reply by ●April 3, 20072007-04-03
Reply by ●April 3, 20072007-04-03
On 3 Apr., 15:15, "Rune Allnor" <all...@tele.ntnu.no> wrote:> On 3 Apr, 14:17, "Andor" <andor.bari...@gmail.com> wrote: > > > On 3 Apr., 13:48, "Rune Allnor" <all...@tele.ntnu.no> wrote: > > > > If it's not there you can't filter it out. Your replies are getting > > > > more mysterious as we go along. > > > > C'mon, Andor. I might expect these sorts of objections from a 1st > > > semester student, but from you? > > > I have no idea what you are talking about. > > I understand that now. > > > > Ok, since it is you, I'll show you by spoon-feeding: > > > Mmmmh. > > > [snip analysis of ramp and ramp + cos] > > > > After you run this script, the k=6 coefficient in the > > > ramp-only spectrum (plotted in blue) has a magnitude > > > on the order of 440 or so, while the ramp + cosine > > > coefficient, plotted in red, has a magnitude of 730. > > > That's very nice. It doesn't have the least to do with our discussion, > > though. > > It has everything to do with this discussion. The OP wanted to > filter his data, which are modeled as a general trend like > the ramp with a cosine superimposed, to extract the cosine.That's also possible.> The excercise showed that you can't extract the cosine > model term by this approach.Of course you can. To filter out a n-th degree polynomial trend, just use a filter with an (n+1)-th order zero at zero. For example, the linear trend can be removed using a second order difference filter. However, we (or rather you) are again digreessing. To cut this short, all I did was to dispute your claim (made in the first post that I replied to) "The stock market data don't comply with the assumtions about data the FIR filter techniques is based on." which is quite clearly wrong, no matter how many FFTs you throw around you. Stock market or not, sequences of numbers can always be filtered with FIRs, and the results are always the same. Regards, Andor
Reply by ●April 3, 20072007-04-03
On 3 Apr., 15:15, "Rune Allnor" <all...@tele.ntnu.no> wrote:> On 3 Apr, 14:17, "Andor" <andor.bari...@gmail.com> wrote: > > > On 3 Apr., 13:48, "Rune Allnor" <all...@tele.ntnu.no> wrote: > > > > If it's not there you can't filter it out. Your replies are getting > > > > more mysterious as we go along. > > > > C'mon, Andor. I might expect these sorts of objections from a 1st > > > semester student, but from you? > > > I have no idea what you are talking about. > > I understand that now. > > > > Ok, since it is you, I'll show you by spoon-feeding: > > > Mmmmh. > > > [snip analysis of ramp and ramp + cos] > > > > After you run this script, the k=6 coefficient in the > > > ramp-only spectrum (plotted in blue) has a magnitude > > > on the order of 440 or so, while the ramp + cosine > > > coefficient, plotted in red, has a magnitude of 730. > > > That's very nice. It doesn't have the least to do with our discussion, > > though. > > It has everything to do with this discussion. The OP wanted to > filter his data, which are modeled as a general trend like > the ramp with a cosine superimposed, to extract the cosine.That's also possible.> The excercise showed that you can't extract the cosine > model term by this approach.Of course you can. To filter out a n-th degree polynomial trend, just use a filter with an (n+1)-th order zero at zero. For example, the linear trend can be removed using a second order difference filter. However, we (or rather you) are again digreessing. To cut this short, all I did was to dispute your claim (made in the first post that I replied to) "The stock market data don't comply with the assumtions about data the FIR filter techniques is based on." which is quite clearly wrong, no matter how many FFTs you throw around you. Stock market or not, sequences of numbers can always be filtered with FIRs, and the results are always the same. Regards, Andor
Reply by ●April 4, 20072007-04-04
On Sun, 01 Apr 2007 20:11:19 -0500, info2007@parse.com (Robert Krten) wrote: (snipped)> >I also fixed the shift cos() multiplication to be a sin() >multiplication and that has helped with the output. > >I will probably take this function and put it into a library. >At that point, I'll validate it with known data... :-) > >Thanks, >-RK > >-- >Robert Krten, Antique computer collector looking for PDP-8 and PDP-8/S >minicomputers; check out their "good home" at www.parse.com/~museumHi Robert, I just now saw this thread. I'm glad your filter is "working". By the way, are your FIR filter coefficients symmetrical? That condition is necessary if you want your filter to be "linear phase". (I'm guessing that you probably do want linear phase.) Although I failed to mention it in the 2nd edition of my book, the guys here have taught me how to make sure the final coefficients (after the "shift multilication") are symmetrical. If you need more info on this issue, please let me know. Also, if you'd like the errata for your copy of my book, let me know by way of a personal E-mail. (Just remove the _BOGUS_ from my E-mail address here.) Robert, I took a quick look at your "museum" web site. NEAT!!! Seeing all those PDP_11s sure brought back some wonderful/miserable memories for me. By the way, somewhere in this Hell-hole I call my office, I have the little "fold-out" cardboard card that lists all the PDP-11 machine codes in octal notation (if I recall correctly). Years ago I keep that card with me at all times (during work) because using it would allow me to check a PDP's memory, accept an ASCII character from the kyboard, send an ASCII character to a monitor screen or a teletype machine. That doesn't sound to impressive, but what it means is that you could perform a fair amount of troubleshooting of the PDP ***from the front panel switches***!!! You could load, say, a dozen machine code instructions in memory, and then tell the CPU to jump to, and execute, those instructions. A VERY POWERFUL TROUBLESHOOTING CAPABILITY! See Ya, [-Rick-] (Sheece. Now if I could just find that PDP programming card!)
Reply by ●April 4, 20072007-04-04
Rick Lyons <R.Lyons@_bogus_ieee.org> wrote:> On Sun, 01 Apr 2007 20:11:19 -0500, info2007@parse.com (Robert Krten) > wrote:> (snipped) > > > >I also fixed the shift cos() multiplication to be a sin() > >multiplication and that has helped with the output. > > > >I will probably take this function and put it into a library. > >At that point, I'll validate it with known data... :-) > > > >Thanks, > >-RK > > > >-- > >Robert Krten, Antique computer collector looking for PDP-8 and PDP-8/S > >minicomputers; check out their "good home" at www.parse.com/~museum> Hi Robert, > I just now saw this thread. > I'm glad your filter is "working".Hi Rick!> By the way, are your FIR filter coefficients > symmetrical? That condition is necessary if > you want your filter to be "linear phase". > (I'm guessing that you probably do want linear > phase.)Yes, I believe they are -- I've kind of put this project on the back burner until the rest of the thread dies down with some kind of answer. :-/ Wow! I sure didn't mean to start the length of discussion I did -- I just want to filter out the sine waves and patterns that I can "plainly see" in the stock market data :-) (Maybe I'll start a new thread, and call it "How to filter stock market data?" -- that way I won't be presupposing FIR's :-))> Although I failed to mention it in the 2nd > edition of my book, the guys here have taught me > how to make sure the final coefficients (after > the "shift multilication") are symmetrical. > If you need more info on this issue, please let > me know. Also, if you'd like the errata for > your copy of my book, let me know by way of > a personal E-mail. (Just remove the _BOGUS_ > from my E-mail address here.)I'll send you an email, thanks!> Robert, I took a quick look at your "museum" web > site. NEAT!!! Seeing all those PDP_11s sure > brought back some wonderful/miserable memories > for me. By the way, somewhere in this Hell-hole > I call my office, I have the little "fold-out" > cardboard card that lists all the PDP-11 machine > codes in octal notation (if I recall correctly). > Years ago I keep that card with me at all times > (during work) because using it would allow me to > check a PDP's memory, accept an ASCII character > from the kyboard, send an ASCII character to > a monitor screen or a teletype machine.> That doesn't sound to impressive, but what it means > is that you could perform a fair amount of > troubleshooting of the PDP ***from the front panel > switches***!!! You could load, say, a dozen > machine code instructions in memory, and then tell > the CPU to jump to, and execute, those instructions. > A VERY POWERFUL TROUBLESHOOTING CAPABILITY!Yes, those were the days. I particularly like being able to fix my own hardware, by replacing a simple gate or transistor, rather than having the "one chip wonder" be declared dead and have to replace 10 million transistors all at once :-)> See Ya, > [-Rick-] > (Sheece. Now if I could just find that PDP > programming card!)www.bitsavers.org surely has scans of them; you could make your own :-) Nice hearing from you! -RK -- Robert Krten, Antique computer collector looking for PDP-8 and PDP-8/S minicomputers; check out their "good home" at www.parse.com/~museum
Reply by ●April 5, 20072007-04-05
On 4 Apr, 20:29, info2...@parse.com (Robert Krten) wrote:> (Maybe I'll start a new thread, and call it "How to > filter stock market data?" -- that way I won't be > presupposing FIR's :-))That's a completely different question. It seems Kalman filters is the name of the game in ecenomy time series analysis, these days. Be warned, though, Kalman filters requires a mathematical background at a completely different level than FIR or IIR filters. Rune
Reply by ●April 5, 20072007-04-05
On Apr 5, 6:17 am, "Rune Allnor" <all...@tele.ntnu.no> wrote:> On 4 Apr, 20:29, info2...@parse.com (Robert Krten) wrote: > > > (Maybe I'll start a new thread, and call it "How to > > filter stock market data?" -- that way I won't be > > presupposing FIR's :-)) > > That's a completely different question. It seems Kalman > filters is the name of the game in ecenomy time series > analysis, these days.yeah, i wonder what store i can go to and pick up one of them Kalman filters? they must be top -of-the-line filters if they be half of what their reputation is.> Be warned, though, Kalman filters requires a mathematical > background at a completely different level than FIR or IIR > filters.something we mortals cannot be expected to have. Kalman filtering also requires a model of the "plant" (as in a state- variable control system that is "completely observable") of which Robert K needs to postulate and what the KF does is provide an optimal (least square error) estimate of the states in that plant, from which Robert K would derive some meaning from the value of those states. conceptually, if the plant was a valid model of the process, he could possibly view a state that would represent (within a probabilistic limit) a future value of some stock or the expected derivative (up or down). i even think that Kalman himself has attempted (perhaps succeeded) in exploring that. in fact, i thought that Rudolf Kalman eventually became a department head of some mathematical-economics department somewhere, but that i don't know and do not know where to find out. anyway, if Robert K is just trying to find periodic behavior in some real-world signal, it might be that linear filtering is the ticket. i might suggest looking into using a bank of comb filters with different periods and see which comb filter lights up significantly more than any of the others. FIR vs. IIR shouldn't be an issue since is sampling rate is pretty slow. he can afford a really long FIR if he wants to do it that way. r b-j
Reply by ●April 5, 20072007-04-05
robert bristow-johnson <rbj@audioimagination.com> wrote:> On Apr 5, 6:17 am, "Rune Allnor" <all...@tele.ntnu.no> wrote: > > On 4 Apr, 20:29, info2...@parse.com (Robert Krten) wrote: > > > > > (Maybe I'll start a new thread, and call it "How to > > > filter stock market data?" -- that way I won't be > > > presupposing FIR's :-)) > > > > That's a completely different question. It seems Kalman > > filters is the name of the game in ecenomy time series > > analysis, these days.> yeah, i wonder what store i can go to and pick up one of them Kalman > filters? they must be top -of-the-line filters if they be half of > what their reputation is.> > Be warned, though, Kalman filters requires a mathematical > > background at a completely different level than FIR or IIR > > filters.> something we mortals cannot be expected to have.> Kalman filtering also requires a model of the "plant" (as in a state- > variable control system that is "completely observable") of which > Robert K needs to postulate and what the KF does is provide an optimal > (least square error) estimate of the states in that plant, from which > Robert K would derive some meaning from the value of those states. > conceptually, if the plant was a valid model of the process, he could > possibly view a state that would represent (within a probabilistic > limit) a future value of some stock or the expected derivative (up or > down). i even think that Kalman himself has attempted (perhaps > succeeded) in exploring that. in fact, i thought that Rudolf Kalman > eventually became a department head of some mathematical-economics > department somewhere, but that i don't know and do not know where to > find out.> anyway, if Robert K is just trying to find periodic behavior in some > real-world signal, it might be that linear filtering is the ticket. i > might suggest looking into using a bank of comb filters with different > periods and see which comb filter lights up significantly more than > any of the others. FIR vs. IIR shouldn't be an issue since is > sampling rate is pretty slow. he can afford a really long FIR if he > wants to do it that way.Thanks, Robert B-J! I was afraid of admitting my complete ignorance of higher math, such as would be required to implement a Kalman filter (the web has tons of stuff, but it's all *way* beyond me -- I'm an embedded realtime control kind of guy). I recently wrote a caller ID modem (1200 baud FSK with 1200 Hz and 2200 Hz filters). The whole idea there was that a sin and cos array for each frequency was generated, and then the incoming pattern convoluted (that's the right term, right?: sum of each input point multiplied by its corresponding sin/cos array point) against that. Whichever one's (1200 or 2200) sum of squares came up higher was the frequency detected. Could I use a similar approach with the frequencies that I'm interested in? My main concern is filter delay (Since this isn't a realtime application, computational expense/delay isn't an issue -- minutes are fine.) I do need to have minimal delay through the filter though, and the output phase needs to line up -- when I seen an uptrend on the various filter outputs, it needs to correspond to what the final sample or two is/are doing. Ideally, I'd like to add up the output sinusoidals and get the original (or a close facsimile) back as a sanity test. I'm reading J M Hurst's 1972 book, with a (granted hokey) title of "The Profit Magic of Stock Transaction Timing", and that's where I'm coming from. In the book, Hurst claims that there are a dozen or so periodic sinusoidals present in most stocks. After reading the text, I can see certain stocks (and yes, their derivatives :-)) that do in fact exhibit this behaviour, so of course I now want to automate the selection process, stick a neural net on the output, and make astounding stock predictions :-) The reason I'm particularly enamoured with that book is because it's the only book that I've ever seen that actually *explains why* things like head-and-shoulders, or double-tops, etc, form and *why* they work the way they do. As far as the analysis goes, I'm interested in periods that are on the order of a few days to a few months -- longer terms are not that important for my application (I'm not an investor, more of a speculator). In his book, Hurst goes on to say that the sinusoidals vary in frequency according to amplitude -- the greater the amplitude, the lower the frequency (all within a band, of course). So, any suggestions that a somewhat competent C programmer, but not a university-level mathematics guy, can understand would be greaty appreciated... :-) Cheers, -RK -- Robert Krten, Antique computer collector looking for PDP-8 and PDP-8/S minicomputers; check out their "good home" at www.parse.com/~museum
Reply by ●April 5, 20072007-04-05
disclaimer: i am no stock analyst or guru. take anything here with a grain of salt. On Apr 5, 8:57 pm, info2...@parse.com (Robert Krten) wrote:> > Thanks, Robert B-J!yer welcome FWIW (i don't think it's worth anything, but hey...).> I was afraid of admitting my complete ignorance of higher math, such > as would be required to implement a Kalman filteryou would have a lot of company. i dunno anything about the Kalman filter they didn't teach us in grad school, i never used it in work, for recreationaly purposes i one tried to implement an idea of Jeffery Risberg to extract optimal (Chowning) FM synthesizer parameters of a given note (the paper, http://www.aes.org/e-lib/browse.cfm?elib=3691 , is around 1980, i was doing this around 1989 when i first had the ability to read an AIFF sound file on my Mac) using the KF. dunno if i just didn't do it right, or if the algorithm made for a better paper than a real implementation (hey, i've been guilty of that also, as in: http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=969581 ) but for whatever reason, the algorithm as implemented came up with complete crap for the amplitude and FM index functions. if applied to an FM synthesis alg, i know it would have sounded worse than dog shit. it might have sounded like it does when your pointer arithmetic gets screwed up and you're playing out samples of opcodes or some other digital data that is not your sound file. so my experience of using KF is very limited and unsuccessful. i now only essentially remember what the fundamental idea was and could not derive the Kalman gain formula (or even use it properly) if you held a gun to my head.> (the web has tons of > stuff, but it's all *way* beyond me -- I'm an embedded realtime control > kind of guy).it's beyond many or most of us. i count myself in the "it's beyond" group.> I recently wrote a caller ID modem (1200 baud FSK with 1200 Hz and 2200 > Hz filters). The whole idea there was that a sin and cos array for > each frequency was generated, and then the incoming pattern convoluted > (that's the right term, right?:we might say "convolved" as a verb. "convoluted" is an adjective.> sum of each input point multiplied by its > corresponding sin/cos array point) against that. Whichever one's (1200 > or 2200) sum of squares came up higher was the frequency detected. > Could I use a similar approach with the frequencies that I'm interested > in? > > My main concern is filter delay (Since this isn't a realtime application, > computational expense/delay isn't an issue -- minutes are fine.)well, if you're trying to out-guess the stock market, this is important. a linear-phase filter that is two weeks long would give you a very nice estimate of some state one week ago. won't that be helpful? :-)> I do need to have minimal delay through the filter though, > and the output phase needs to line up -- when I seen an uptrend on > the various filter outputs, it needs to correspond to what the final > sample or two is/are doing. Ideally, I'd like to add up the output > sinusoidals and get the original (or a close facsimile) back as a > sanity test.so you want a bank of complementary filters (filters that when you add up the outputs, you get a "wire")? a bunch of bandpass filters that are staggered in frequency (or maybe log frequency)? sounds like a multiband filter bank. we do this in audio, but the time constants are a lot shorter (or the resonant frequencies are a lot longer). to get that minimal delay, you will need minimum-phase filters, but there is no way to add up a bunch of non-trivial minimum phase filters and get a wire. at least, not over first-order. at least, i don't think so (now that i'm thinking about it, there might be, but they still might not be filters you want).> I'm reading J M Hurst's 1972 book, with a (granted hokey) title of "The > Profit Magic of Stock Transaction Timing", and that's where I'm coming > from. In the book, Hurst claims that there are a dozen or so periodic > sinusoidals present in most stocks. After reading the text, I can see > certain stocks (and yes, their derivatives :-)) that do in fact exhibit > this behaviour, so of course I now want to automate the selection > process, stick a neural net on the output, and make astounding stock > predictions :-) > > The reason I'm particularly enamoured with that book is because it's > the only book that I've ever seen that actually *explains why* things > like head-and-shoulders, or double-tops, etc, form and *why* they work > the way they do. > > As far as the analysis goes, I'm interested in periods that are on > the order of a few days to a few months -- longer terms are not > that important for my application (I'm not an investor, more of > a speculator).well, you might want to see cyclical behavior that is not necessarily *sinusoidal*. it could be *any* periodic function that such a trend follows. in the audio-DSP world, when we want to filter out a periodic function of a known frequency, we use a comb filter. they use delay lines and there are both FIR comb filters and IIR comb filters. it's not too hard to explain, but try looking it up.> In his book, Hurst goes on to say that the sinusoidals vary in > frequency according to amplitude -- the greater the amplitude, the > lower the frequency (all within a band, of course).yeah, that behavior i know nothing about and i am not sure how that information could be put to use.> So, any suggestions that a somewhat competent C programmer, but not a > university-level mathematics guy, can understand would be greaty > appreciated... :-)do you know how to write a C program to implement a delay line (using the modulo % operator on the array index - you could also mask with the bitwise & operator if your buffer is a power of 2 in length)? try implementing a bunch of different length delay lines in parallel, all fed by the same input. then combine (weighted addition) the most recent input with the sample that falls off the edge of your circular queue, and you have a bank of comb filters. if one of the comb filters has output that is much larger than the others, i think you could claim that there is a periodic trend in your data. FWIW, all this could just be crap. r b-j
Reply by ●April 5, 20072007-04-05
On Apr 5, 10:09 pm, r...@ycrdi.com wrote:>aw shit! i did it again! i forgot to change my Google personality to rbj@audioimagination.com. now i'm gonna get a shitload of spam at my work email account again. fuck! r b-j if i ever see a spam-bot walking around, i'm gonna get a 50-caliber gun and blow it to smithereens. dammit!







