English Amiga Board Help with sine regression
 User Name Remember Me? Password
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 26 June 2008, 17:33 #1 Ed Cruse Registered User   Join Date: Sep 2007 Location: Las Cruces, USA Age: 65 Posts: 351 Help with sine regression Can anybody point me in the right direction as to how to do a sine regression. I would like to write C code for my Amiga to do it. I’ve been searching the internet for several days and all I can come up with is that TI calculators do it and how to estimate it. What I would like is a numerical method that will give an exact answer, as opposed to a convergent method. One method I did come across was to do a Direct Fourier Transform, which my calculator does, but the numbers that come out don’t mean anything to me. I don’t see how you get the sine constants (amp, phase, freq, offset) for each sine wave in the signal. Any information will be appreciated. Thank you.
 27 June 2008, 01:01 #2 Photon Moderator   Join Date: Nov 2004 Location: Hult / Sweden Posts: 4,591 It's a "sum" of quotients. I made one once, unfortunately it's on a crashed harddisk that takes 22 hours to restore, so I've never gotten round to it (yet).
27 June 2008, 16:32   #3
Ed Cruse
Registered User

Join Date: Sep 2007
Location: Las Cruces, USA
Age: 65
Posts: 351
Quote:
 Originally Posted by Photon It's a "sum" of quotients. I made one once, unfortunately it's on a crashed harddisk that takes 22 hours to restore, so I've never gotten round to it (yet).
Thank you for replying, but I'm still in the dark. Could you please be a little more specific if you can remember. As a test I generated 8 data points for a simple sine wave, did a FFT on my calculator and came up with numbers that don't mean anything to me. The output format is (real part, imaginary part).

0--------->(0,0)
0.707----->(0,-4)
1--------->(0,0)
0.707----->(0,0)
0--------->(0,0)
-0.707---->(0,0)
-1-------->(0,0)
-0.707---->(0,4)

Sorry for the crazy looking table above, the editor removed all the spaces so I used dashes and a right arrow.

Thank you.

 27 June 2008, 18:05 #4 eLowar Citizen of Elthesh   Join Date: Sep 2003 Location: London, UK Posts: 949 Well, while I'd have to do the math to see where the exact numbers come from, it does make sense. A sine function contains exactly one frequency, which is why you get one spike in fourier space (plus its mirror image with the opposite sign in the imaginary part). http://mathworld.wolfram.com/FourierTransformSine.html See? Two delta functions on opposite sides with opposite signs before i.
28 June 2008, 17:50   #5
Ed Cruse
Registered User

Join Date: Sep 2007
Location: Las Cruces, USA
Age: 65
Posts: 351
Quote:
 Originally Posted by eLowar Well, while I'd have to do the math to see where the exact numbers come from, it does make sense. A sine function contains exactly one frequency, which is why you get one spike in fourier space (plus its mirror image with the opposite sign in the imaginary part). http://mathworld.wolfram.com/FourierTransformSine.html See? Two delta functions on opposite sides with opposite signs before i.
So, you're saying that the output of the transform is a spectrum (frequency verses amplitute)? Since I used y=sin(x) to create the data, shouldn't the amplitude by -1 and 1? If the imaginary part is amplitude what's the real part, phase?

I checked out the link, good stuff, but way over my head. What I really need is something that tells me how to take a signal (made up of data points) and derive all the sin functions that make it up, so I can write the code. The math theory is just to much for me. I had calculus but I didn't do so well, even though I understand it I have to use my calculator to do the calculations.

Thank you for the link, I put it into my favorites so I can keep going back and studying, it looks like a good site in general.

 28 June 2008, 18:00 #6 eLowar Citizen of Elthesh   Join Date: Sep 2003 Location: London, UK Posts: 949 Well, I expect (again without really feeling like looking into it myself, I'm rather busy right now) you probably used integers for x, which basically means degrees, while the sin() function probably expects radians. Otherwise I'd have to (tentatively) agree with your assessment. Yes, in fourier space you see the amplitude at frequencies, rather than locations. The frequency of each sine wave in the signal corresponds to the distance of the delta spikes from the center, the amplitude should (if I'm not mistaken) correspond to the amplitude in fourier space. Phase is more complicated, I believe (adding some exponential factor). Note that even if these statements are correct they're still just generalities and there may e.g. be constant factors missing. It's been a while since I've properly worked with this and I'm a little rusty. A proper mathematician could probably be of more help.
29 June 2008, 02:41   #7
Ed Cruse
Registered User

Join Date: Sep 2007
Location: Las Cruces, USA
Age: 65
Posts: 351
Quote:
 Originally Posted by eLowar Well, I expect (again without really feeling like looking into it myself, I'm rather busy right now) you probably used integers for x, which basically means degrees, while the sin() function probably expects radians. Otherwise I'd have to (tentatively) agree with your assessment. Yes, in fourier space you see the amplitude at frequencies, rather than locations. The frequency of each sine wave in the signal corresponds to the distance of the delta spikes from the center, the amplitude should (if I'm not mistaken) correspond to the amplitude in fourier space. Phase is more complicated, I believe (adding some exponential factor). Note that even if these statements are correct they're still just generalities and there may e.g. be constant factors missing. It's been a while since I've properly worked with this and I'm a little rusty. A proper mathematician could probably be of more help.

Thank you for the info, I'm still in the dark but the light is starting to come on.

I used degrees in double float, my calculator is set in degree mode so it should have worked correctly. I did not know that the frequency is a delta from the center, I thought if was delta from the left or top.

Seems like everybody has done this at one time or another but haven't in a long time and don't remember. I even asked DrMath.com but they haven't gotten back and it's been a couple of days, so they probably won't.

Thanks again.

 29 June 2008, 02:46 #8 eLowar Citizen of Elthesh   Join Date: Sep 2003 Location: London, UK Posts: 949 Well, look at the formula, k0 is the period (and 1/k0 the frequency; although maybe the other way around ), and the delta spikes are shifted by k0, left and right from the origin (in the imaginary part). I'm unsure about the rest. I might think more about it next week if there's still a need, I should have a little more time then.
 29 June 2008, 03:10 #9 Photon Moderator   Join Date: Nov 2004 Location: Hult / Sweden Posts: 4,591 Ah! Found it in one of my yellowed notebooks... sin x = x - (x^3 / 3!) + (x^5 / 5!) - (x^7 / 7!) + (x^9 / 9!) ... where ^ is "raised to the power of", ie. x^3 = x*x*x and ! is factorial, ie. 4!=1*2*3*4 Didn't find the asm for it, though. IIRC the angle x was in radians as a signed 16-bit integer and I swapped it down for each "power" except last, and then I had a simple list of precalced factorials longwords, shifted to keep the accumulated sum of quotients within longword bounds. The result was a signed integer where "1" was \$7fffffff, and I think you got one "bit" of result precision for two iterations, so 32 iterations should give 16 bits precision, i.e. 4-5 decimal places.
29 June 2008, 17:30   #10
Ed Cruse
Registered User

Join Date: Sep 2007
Location: Las Cruces, USA
Age: 65
Posts: 351
Quote:
 Originally Posted by eLowar Well, look at the formula, k0 is the period (and 1/k0 the frequency; although maybe the other way around ), and the delta spikes are shifted by k0, left and right from the origin (in the imaginary part). I'm unsure about the rest. I might think more about it next week if there's still a need, I should have a little more time then.

I see what you are saying. I'm going to play around with my calculator with two waves and see what happens. Thank you, and there will probably will be a need for more info, so if you think of more info please let me know.

29 June 2008, 17:45   #11
Ed Cruse
Registered User

Join Date: Sep 2007
Location: Las Cruces, USA
Age: 65
Posts: 351
Quote:
 Originally Posted by Photon Ah! Found it in one of my yellowed notebooks... sin x = x - (x^3 / 3!) + (x^5 / 5!) - (x^7 / 7!) + (x^9 / 9!) ... where ^ is "raised to the power of", ie. x^3 = x*x*x and ! is factorial, ie. 4!=1*2*3*4 Didn't find the asm for it, though. IIRC the angle x was in radians as a signed 16-bit integer and I swapped it down for each "power" except last, and then I had a simple list of precalced factorials longwords, shifted to keep the accumulated sum of quotients within longword bounds. The result was a signed integer where "1" was \$7fffffff, and I think you got one "bit" of result precision for two iterations, so 32 iterations should give 16 bits precision, i.e. 4-5 decimal places.

It looks to me like what you are showing me is a infinite series which yields sin(x). If I'm not mistaken then that's not what I need, the Amiga math library will do that. If I am mistaken then I appologies, but I don't understand.

What I'm trying to do is do a sin function best fit curve, and I think I can do this by using a fourier transform, but I'm having trouble figuring out how to use the results that my calculator gives me. Before I write code to do a fourier transform I need to know how to use the results. Again if I'm mistaken then I appologies for not being smart enough to understand. I do appreciate the effort you are making.

29 June 2008, 18:03   #12
eLowar
Citizen of Elthesh

Join Date: Sep 2003
Location: London, UK
Posts: 949
Quote:
 Originally Posted by Ed Cruse It looks to me like what you are showing me is a infinite series which yields sin(x). If I'm not mistaken then that's not what I need, the Amiga math library will do that. If I am mistaken then I appologies, but I don't understand.
That's correct, it's a Taylor series for sin(x).

Edit: See e.g. http://www.ucl.ac.uk/Mathematics/geo...es/ser121.html for details.

 29 June 2008, 22:40 #13 Photon Moderator   Join Date: Nov 2004 Location: Hult / Sweden Posts: 4,591 Oh, I thought you wanted regression, ie. fit data to a curve, and read "sine regression" as some function that describes or fits a sine curve. I saw now that you don't want functions that converge, my bad. So the application is signal analysis?
30 June 2008, 02:06   #14
Ed Cruse
Registered User

Join Date: Sep 2007
Location: Las Cruces, USA
Age: 65
Posts: 351
Quote:
 Originally Posted by Photon Oh, I thought you wanted regression, ie. fit data to a curve, and read "sine regression" as some function that describes or fits a sine curve. I saw now that you don't want functions that converge, my bad. So the application is signal analysis?
It's signal analysis, but my data is not a real siganl. I've noticed over the years that data seems to be either a straight line or waves. So I'm trying to do a sine regression which is a best fit sine curve for a data set. I think I have figured it out, the next message will explain.

Thank you very much for your help.

 30 June 2008, 02:15 #15 Ed Cruse Registered User   Join Date: Sep 2007 Location: Las Cruces, USA Age: 65 Posts: 351 eLowar, I think I’m making a lot of head way with the Fourie Transform. Basically I’m using only the positive side of the Fourie space. The data point furthest from the origin is a frequency of one, and then goes two, three, four, and so on towards the origin. The amplitude and phase appear to be combined into the real and imaginary parts of the output. After many hours I’ve come up with what I think are the formulas. First the numbers have to be divided by the number of data points in the positive Fourie space and then the following formulas seem to apply. I’m using 32 data points for the input, so I get 32 data points out, which means the positive space has 16 data points. Phase=atan(rp/ip) Amp=sqrt(rp^2+ip^2) It appears the outputs, after being divided by 16, are the sides of a right triangle, the real part is the opposite side and the imaginary part is the adjacent side. The phase is the angle, the amplitude is the hypotenuse. Does this seem reasonable to you? Thank you very much for your help, you got me going in the right direction.

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 Thread Tools

 Similar Threads Thread Thread Starter Forum Replies Last Post pmc Coders. Tutorials 95 02 July 2017 17:40 Crashdisk support.WinUAE 3 01 February 2013 21:09 mark_k support.WinUAE 15 28 January 2013 19:07 bobster Coders. Tutorials 16 17 October 2012 13:11

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News Main     Amiga scene     Retrogaming General Discussion     Nostalgia & memories Support     New to Emulation or Amiga scene         Member Introductions     support.WinUAE     support.WinFellow     support.OtherUAE     support.FS-UAE         project.AmigaLive     support.Hardware         Hardware mods         Hardware pics     support.Games     support.Demos     support.Apps     support.Amiga Forever     support.Amix     support.Other Requests     request.UAE Wishlist     request.Old Rare Games     request.Demos     request.Apps     request.Modules     request.Music     request.Other     Looking for a game name ?     Games images which need to be WHDified abime.net - Hall Of Light     HOL news     HOL suggestions and feedback     HOL data problems     HOL contributions abime.net - Amiga Magazine Rack     AMR news     AMR suggestions and feedback     AMR data problems     AMR contributions abime.net - Home Projects     project.Amiga Lore     project.EAB     project.IRC     project.Mods Jukebox     project.Wiki abime.net - Hosted Projects     project.aGTW     project.APoV     project.ClassicWB     project.Jambo!     project.Green Amiga Alien GUIDES     project.Maptapper     project.Sprites     project.WinUAE - Kaillera Other Projects     project.Amiga Demo DVD     project.Amiga Game Factory     project.CARE     project.EAB File Server     project.CD32 Conversion     project.Game Cover Art         GCA.Feedback and Suggestions         GCA.Work in Progress         GCA.Cover Requests         GCA.Usefull Programs         GCA.Helpdesk     project.KGLoad     project.MAGE     project.Missing Full Shareware Games     project.SPS (was CAPS)     project.TOSEC (amiga only)     project.WHDLoad         project.Killergorilla's WHD packs Misc     Amiga websites reviews     MarketPlace         Swapshop     Collections     EAB's competition Coders     Coders. General         Coders. Releases         Coders. Tutorials     Coders. Asm / Hardware     Coders. System         Coders. Scripting         Coders. Nextgen     Coders. Language         Coders. C/C++         Coders. AMOS         Coders. Blitz Basic     Coders. Contest         Coders. Entries Off Topic     OT - General     OT - Entertainment     OT - Sports     OT - Technical     OT - Gaming

All times are GMT +2. The time now is 10:56.

 -- EAB3 skin ---- EAB2 skin ---- Mobile skin Archive - Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.08033 seconds with 13 queries