473,729 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Frequency spectrum with fft of a real valued array...?



Dear all,

I need to do a FFT on an array of 20k real values. Origin of the sampled
data is a sinus wave with light harmonics.
The goal is an frequency spectrum with the magnitudes of the first 50.
harmonics.

I addressed python like:

test_arr = src_data_dict[ channel ][0:19599]
target_data_dic t[ channel ] = FFT.fft(test_ar r,n=50,axis=-1)

This results in an array of complex values but with unexpected big
coefficients...
(much higher than the original signal magnitudes)
How do I get the absolute magnitudes of the harmonics, which are much
lower than the
resulting absolute values of the coefficients?

The result should be like this:

1.harmonic (50 Hz) 1,0
2.harmonic (100 Hz) 0,01
3.harmonic (100 Hz) 0,08
4.harmonic (100 Hz) 0,0035
etc.
at the moment I get a resulting array like:

CH1
(1729.80103418+ 0j)
(366.689810532+ 19.5196963754j)
(370.688444025+ 32.162562652j)
(372.122246668+ 46.9545880507j)
(379.273599053+ 59.0724599622j)
(369.889589421+ 75.9247281559j)
(381.070551892+ 99.07345873j)
(378.800462354+ 106.761629308j)
(375.014128346+ 131.34177586j)
(389.110601354+ 149.320740829j)
(389.23247472+1 58.909042086j)
(398.875237165+ 197.86980788j)
(397.927158223+ 196.858459101j)
(402.455325066+ 234.651276425j)
(411.599088579+ 256.32156894j)
(414.469935576+ 254.512014918j)
(417.198515262+ 291.400509132j)
(426.745545674+ 320.769421334j)
(433.987466212+ 321.929780157j)
(446.124386798+ 350.810581686j)
(455.876025379+ 383.099789898j)
(458.083277747+ 405.592129477j)
(470.908512117+ 433.929598454j)
(482.083855098+ 468.256188814j)

What does it mean to me? How do I get to the wanted frequenca spectrum???
...

btw The maximum magnitudes of the original data are app. 70 peak

Thanks in advance for your help!!!

Regards Holger
Jan 11 '07 #1
2 5167
Holger wrote:
What does it mean to me? How do I get to the wanted frequenca spectrum???
It's packed in the conventional FFT format. Here is a function in numpy (the
successor to Numeric, which I assume that you are using) that generates the
corresponding frequencies in the same packed format:

In [324]: import numpy

In [325]: numpy.fft.fftfr eq?
Type: function
Base Class: <type 'function'>
Namespace: Interactive
File:
/Library/Frameworks/Python.framewor k/Versions/2.5/lib/python2.5/site-packages/numpy-1.0.2.dev3507-py2.5-macosx-10.4-i386.egg/numpy/fft/helper.py
Definition: numpy.fft.fftfr eq(n, d=1.0)
Docstring:
fftfreq(n, d=1.0) -f

DFT sample frequencies

The returned float array contains the frequency bins in
cycles/unit (with zero at the start) given a window length n and a
sample spacing d:

f = [0,1,...,n/2-1,-n/2,...,-1]/(d*n) if n is even
f = [0,1,...,(n-1)/2,-(n-1)/2,...,-1]/(d*n) if n is odd
--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Jan 11 '07 #2
Hello Robert!

Thank you for your tips. They were very useful.

Bye Holger
Am 11.01.2007, 19:08 Uhr, schrieb Robert Kern <ro*********@gm ail.com>:
Holger wrote:
>What does it mean to me? How do I get to the wanted frequenca
spectrum???

It's packed in the conventional FFT format. Here is a function in numpy
(the
successor to Numeric, which I assume that you are using) that generates
the
corresponding frequencies in the same packed format:

In [324]: import numpy

In [325]: numpy.fft.fftfr eq?
Type: function
Base Class: <type 'function'>
Namespace: Interactive
File:
/Library/Frameworks/Python.framewor k/Versions/2.5/lib/python2.5/site-packages/numpy-1.0.2.dev3507-py2.5-macosx-10.4-i386.egg/numpy/fft/helper.py
Definition: numpy.fft.fftfr eq(n, d=1.0)
Docstring:
fftfreq(n, d=1.0) -f

DFT sample frequencies

The returned float array contains the frequency bins in
cycles/unit (with zero at the start) given a window length n and a
sample spacing d:

f = [0,1,...,n/2-1,-n/2,...,-1]/(d*n) if n is even
f = [0,1,...,(n-1)/2,-(n-1)/2,...,-1]/(d*n) if n is odd

Jan 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2150
by: christopher diggins | last post by:
I would like to survey how widespread the usage of smart pointers in C++ code is today. Any anecdotal experience about the frequency of usage of smart pointer for dynamic allocation in your own code or other people's code you have come across would be appreciated. I am also trying to identify the likelihood nad frequency of scenarios where smart pointer solutions would not be appropriate, i.e. for some reason such as performance or...
2
4435
by: riscy | last post by:
Has anyone know good webpage or book covering C# code in transformation of real time or sampled time data into FFT spectrum display (using GDI+). I like to learn FFT processing in abc way...can anyone point me good book or student course booklet. Thanks.
3
10425
by: Neil West | last post by:
Earlier this week I was tasked with displaying some data from an excel spreadsheet, the details of which aren't important. I decided to display the range of values with a cold-to-hot color model which would then be used to color objects in Adobe InDesign via scripting. Again, none of this is important, ignore the software names, this is just an introduction. Since I have a deep dislike of number-crunching, I didn't want to figure out...
19
3139
by: jason_box | last post by:
I'm alittle new at C and I'm trying to write a simple program that will record the frequency of words and just print it out. It is suppose to take stdin and I heard it's only a few lines but I'm not sure where to start. The only example I have to work with is if you ran the program say: File list contains: This is a test.
6
2643
by: Harryrun | last post by:
Hello am a beginner in programming and I came to a problem with a question in which I need to calculate the frequency of appearance of marks. I have used an array to store the marks but can only find the frequency of the first mark.Complication come along as I try for the others.
11
2321
by: frizzle | last post by:
Hi there, I need a function to prevent a page from being loaded too often too fast. So say, one is only allowed to refresh a single page 5 times in 10 seconds, or 10 times in 5 seconds (or whatever ... ). If the load frequency exceeds that, the site calls exit(); And a message is displayed. Just like Expression Engine does ... This way i want to protect the DB from being queried rediculously
7
4054
by: Udhay | last post by:
How to get the frequency of an audio file and how to separate the low and high frequency of an audio file
1
2555
by: ADHaughton | last post by:
i have an array pages = ; the user is asked to enter a word 'w', which is then searched for in the above array. I want the frequency of that word in pages outputed, then the frequency of the same word in pages outputed, and so on. I dont know where to start, if anyone could post some sample code for me to see what i need to do, that would be greatly appreciated.
1
4939
by: shgu0501 | last post by:
hi I'm supposed to do a frequency array and find mode,median and count, but without storing the actual data in an array. I am able to build a frequency array but I can't return the mode since I am not supposed to store the actual value in an array. Please help me with this problem. Thank you Guinness #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std;
0
8913
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.