HP Forums
Spectrum analysis (Fourier) - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Spectrum analysis (Fourier) (/thread-4450.html)



Spectrum analysis (Fourier) - Aries - 07-29-2015 12:13 PM

Hello everyone,
let's suppose we have the following signal: f(t)=4+(4/pi)*sin(2*pi*800*t)+(4/(3*pi))*sin(2*pi*2400*t)+(4/(5*pi))*sin(2*pi*4000*t).
Ok, this is the resulting waveform (time domain, 4 is the average value):

[Image: th_170958111_waveform_122_586lo.jpg]

Now the (banal) question is, how can I determine (i.e. to plot) the spectrum (in the frequency domain) of the function on the Prime, something like this below ?

[Image: th_171487382_spectrum_122_134lo.jpg]

Any hint would be helpful.
TIA and best,

Aries


RE: Spectrum analysis (Fourier) - Brad Barton - 07-30-2015 02:29 AM

You're looking for the FFT (Fast Fourier Transform) algorithm. I'd give you more info, but I've loaned out the book I had for it. Google FFT, and you should be able to find what you're looking for.

There are some constraints, such as needing 2^n digitized samples and a couple other things, but it's definitely doable.


RE: Spectrum analysis (Fourier) - Aries - 08-12-2015 11:52 AM

Thanks for your help, Brad, you're right, FFT algorithm is really what I was looking for and I've found it:
http://www.codeproject.com/Articles/9388/How-to-implement-the-FFT-algorithm
Now I hope to succeed in implementing the Danielson-Lanzcos algorithm into the HP Prime.
Best,

Aries ;-)


RE: Spectrum analysis (Fourier) - toshk - 08-13-2015 09:43 PM

(i don't have Hp prime to try it.) but works on Emulator.
the App assumes that you place your signal function on F0(X).
visualize your signal function (play with scales/auto zoom or whatever you want) for better representation of the signal. Type
>>Spect>>Enter.
[attachment=2424]
[attachment=2425]
[attachment=2426]
[attachment=2427]
PHP Code:
#pragma mode( separator(.,;) integer(h32) )
SamX();
dftY();
Set();
export Spect()
BEGIN
local dmin
,dmax,dx;
dmin:=Function.Xmin;
dmax:=Function.Xmax;
dx:=(dmax-dmin)/1024;
L0:=makelist(X,X,dmin,dmax,dx);
SamX();
dftY();
L5:=makelist(X,X,0,1/dx,(1/dx)/1025);
Set();
END;

#cas
SamX()
BEGIN
L1
:=F0(L0);
END;
#end

#cas
dftY()
BEGIN
local n
;
L4:=mat2list(fft(L1));
FOR 
n FROM 1 TO size(L4STEP 1 DO
L4(n):=approx(abs(L4(n))*(2/1024));END;
END;
#end

Set()
BEGIN
startapp
("Statistics 1Var");
local n;
FOR 
n FROM 1 TO 64 STEP 1 DO
L8(n):=L5(n);L9(n):=L4(n);end;
D1:=L8;D2:=L9;

Statistics_1Var.H1:={'D2','D1','5'};
CHECK(1);
startview(1,1);
END



RE: Spectrum analysis (Fourier) - Aries - 08-14-2015 08:48 AM

Thanks for your great app, toshk, very very kind of you, it's just what I was looking for and thanks for your great tools on control systems design and analysis (Bode, Nyquist and Nichols charts) too ;-)
What about Routh-Hurwitz and the root-locus methods ?
Are you going to implement those on your future versions ?
Happy August holidays,

Aries ;-)


RE: Spectrum analysis (Fourier) - DrD - 08-14-2015 09:37 AM

The posted code has a syntax error: H1:={'D2','D1','5'}; in the Set() procedure.
I think this is due to the use of H1 as a list variable, which is a global reserved variable of type real.

-Dale-


RE: Spectrum analysis (Fourier) - toshk - 08-14-2015 04:33 PM

(08-14-2015 09:37 AM)DrD Wrote:  The posted code has a syntax error: H1:={'D2','D1','5'}; in the Set() procedure.
I think this is due to the use of H1 as a list variable, which is a global reserved variable of type real.

-Dale-
Open Statistics 1var
Shift>>1
recompile the empty Statistics 1Var.
and recompile my code too.


RE: Spectrum analysis (Fourier) - toshk - 08-14-2015 05:06 PM

(08-14-2015 08:48 AM)Aries Wrote:  Thanks for your great app, toshk, very very kind of you, it's just what I was looking for and thanks for your great tools on control systems design and analysis (Bode, Nyquist and Nichols charts) too ;-)
What about Roth-Hurwitz and the root-locus methods ?
Are you going to implement those on your future versions ?
Happy August holidays,

Aries ;-)
My thoughts:
For Root-Locus method i think Geometric App is a good candidate. but not animated enough to move points along a path. or move a set of conjugate pairs to its new locations.
Also too many rules associated with this method...nevertheless if done on Matlab is doable on temperament Prime.(just less real estate screen).

Roth-Hurwitz: i always wanted to implement that on prime...one of these days i will.
i tend to use Ackermann's method (space vector) for calculating sensitivity gain K.


RE: Spectrum analysis (Fourier) - Tim Wessman - 08-14-2015 05:46 PM

(08-14-2015 04:33 PM)toshk Wrote:  Open Statistics 1var
Shift>>1
recompile the empty Statistics 1Var.
and recompile my code too.

Hello,

It is always a good idea to fully qualify your app functions - especially for something being shared.

Statistics_1Var.H1 would work no matter where the user might be.


RE: Spectrum analysis (Fourier) - toshk - 08-14-2015 06:24 PM

(08-14-2015 05:46 PM)Tim Wessman Wrote:  
(08-14-2015 04:33 PM)toshk Wrote:  Open Statistics 1var
Shift>>1
recompile the empty Statistics 1Var.
and recompile my code too.

Hello,

It is always a good idea to fully qualify your app functions - especially for something being shared.

Statistics_1Var.H1 would work no matter where the user might be.

Noted.....and fixed. Thanks.
The code was meant for Spectrum(App) based on Statistics_2vars, then to be based on Statistics_1var and finally it striped it done to just app.
Any chance to bring back fine(.) or fine dash(-) or tinnier version of the icons in Statistics_2var App? (real estate price is less attractive with is jumbo icons [attachment=2433] in some plots sometimes).


RE: Spectrum analysis (Fourier) - Aries - 09-06-2015 12:17 PM

(08-14-2015 05:06 PM)toshk Wrote:  
(08-14-2015 08:48 AM)Aries Wrote:  Thanks for your great app, toshk, very very kind of you, it's just what I was looking for and thanks for your great tools on control systems design and analysis (Bode, Nyquist and Nichols charts) too ;-)
What about Roth-Hurwitz and the root-locus methods ?
Are you going to implement those on your future versions ?
Happy August holidays,

Aries ;-)
My thoughts:
For Root-Locus method i think Geometric App is a good candidate. but not animated enough to move points along a path. or move a set of conjugate pairs to its new locations.
Also too many rules associated with this method...nevertheless if done on Matlab is doable on temperament Prime.(just less real estate screen).

Roth-Hurwitz: i always wanted to implement that on prime...one of these days i will.
i tend to use Ackermann's method (space vector) for calculating sensitivity gain K.

Thanks toshk, great ideas and I'm looking forward to your updates ;-)
Best,

Aries :-)