Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : CMM2: Option Base bug in MATH FFT ?
Author | Message | ||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
Hi Peter, Found this whilst working with Volhout's MATH test code: > 480MHz Colour Maximite 2 G2 MMBasic Version 5.07.01RC2 Copyright 2011-2021 Geoff Graham Copyright 2016-2021 Peter Mather > list "fft_bug.bas" Option Default None Option Explicit Const BASE% = Val(Mm.CmdLine$) Option Base BASE% Const NUM_SAMPLES% = 512 Dim sin_amp2!(NUM_SAMPLES% + BASE% - 1) Dim dft!(2 + BASE% - 1, NUM_SAMPLES% + BASE% - 1) Dim i% For i% = BASE% to NUM_SAMPLES% + BASE% - 1 sin_amp2!(i%) = 2 * Sin(2 * Pi * i% / NUM_SAMPLES%) Next Math Fft sin_amp2!(), dft!() Print Math(Max dft!()) > run "fft_bug.bas", 1 511.9614473 > run "fft_bug.bas", 0 512 Assuming it's a thing (i.e. I haven't just confused the hell out of myself with Option Base) and you fix it could I please have an updated copy of the MATH source to integrate with MMB4L. Thanks, Tom Edited 2021-09-19 18:33 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
I'll leave you to find the bug in your test program (HINT try comparing sin_amp2!() in both cases) |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
D'oh! Thanks Peter. Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
If you look at the imaginary component of the entry with 511.9614473 it is 6.2830 take the square root of the sum of squares of both numbers and you get 512. Your error introduced a phase shift hence the difference and the non-zero imaginary component |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
Thanks Peter. I vaguely remember someone saying "Fourier Transform" in my first year of university, but for the remainder and the 20+ years since they have never reared their head in my career. Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Print this page |