Finding Index for 0Hz on RF Spectrum

  • Thread starter Thread starter Erenjaeger
  • Start date Start date
  • Tags Tags
    Array Index
Click For Summary
The discussion focuses on finding the index of 0Hz in an RF spectrum frequency graph using Python. The user initially attempted to use `np.argmin` to identify the index but realized it only confirms that the lowest frequency is 0. Suggestions include iterating through the frequency array to locate the index of 0, with a provided code example demonstrating this approach. The user encountered issues when trying to apply the code to their specific array, "f2," and sought clarification on how to properly reference it. The conversation emphasizes the importance of directly iterating over the existing array rather than creating a new one.
Erenjaeger
Messages
141
Reaction score
6

Homework Statement


Find the index corresponding to 0Hz on my RF spectrum vs frequency garph

Homework Equations


using np.argmax or np.argmin [/B]

The Attempt at a Solution


np.argmin just gives the proof that the lowest value in frequency array plotted on x-axis is 0, but now i need to find the index in the array where this happens so i can set the RF spectrum to 0 at that value in order to determine frep or a laser. [/B]
 
Physics news on Phys.org
Erenjaeger said:

Homework Statement


Find the index corresponding to 0Hz on my RF spectrum vs frequency garph

Homework Equations


using np.argmax or np.argmin [/B]

The Attempt at a Solution


np.argmin just gives the proof that the lowest value in frequency array plotted on x-axis is 0, but now i need to find the index in the array where this happens so i can set the RF spectrum to 0 at that value in order to determine frep or a laser. [/B]
in python 3 btw
 
Erenjaeger said:

Homework Statement


Find the index corresponding to 0Hz on my RF spectrum vs frequency garph

Homework Equations


using np.argmax or np.argmin [/B]

The Attempt at a Solution


np.argmin just gives the proof that the lowest value in frequency array plotted on x-axis is 0, but now i need to find the index in the array where this happens so i can set the RF spectrum to 0 at that value in order to determine frep or a laser. [/B]
Can't you just iterate through the array, keeping track of what index you're on, and see when the array value is 0?
 
Mark44 said:
Can't you just iterate through the array, keeping track of what index you're on, and see when the array value is 0?
Not sure how you would code that though I have to write a piece of code that does it, seems simple but I can't find any information on how to find the index where frequency is 0
 
Here's an example of what I'm talking about:
Python:
import array

arr0 = array.array('i', [3, 17, -1, 0, 5, 23, 18])
found = False

for i in range(len(arr0)):
   if arr0[i] == 0:
      found = True
      print("Found 0 at index ", i)
if found == False:
   print("Could not find 0")
If one of the values in the array happens to be zero, this code prints the corresponding index where it was found. If the array doesn't contain 0, the code displays a message that zero couldn't be found.
 
Mark44 said:
Here's an example of what I'm talking about:
Python:
import array

arr0 = array.array('i', [3, 17, -1, 0, 5, 23, 18])
found = False

for i in range(len(arr0)):
   if arr0[i] == 0:
      found = True
      print("Found 0 at index ", i)
if found == False:
   print("Could not find 0")
If one of the values in the array happens to be zero, this code prints the corresponding index where it was found. If the array doesn't contain 0, the code displays a message that zero couldn't be found.
The array is stored under a variable "f2" which is the x-axis and then "RF signal" which is the y axis, I tried running your code with f2 as the array but it didn't run. any idea why that might have been?
 
Can you show the code and the error message (or whatever was the result of running the code)?
 
mfb said:
Can you show the code and the error message (or whatever was the result of running the code)?
Yep! attached is the screen shot and also I printed the array "f2" so you could get an idea of what it consists of.
22883489_1503914236355013_1819086435_n.png
 

Attachments

  • 22883489_1503914236355013_1819086435_n.png
    22883489_1503914236355013_1819086435_n.png
    25 KB · Views: 813
Erenjaeger said:
Yep! attached is the screen shot and also I printed the array "f2" so you could get an idea of what it consists of.
View attachment 213956
I thought it might be taking f2 as a single element of the array rather than an array itself because that error message about length-1 arrays?
 
  • #10
What exactly do you expect "arr0=array.array('i',[f2])" to do? Why don't you iterate over f2 and get rid of arr0?
 
  • #11
In my example, I created the array named arr0. This array contains integers, which is the reason for 'i' in the statement arr0 = array.array('i', ...). Since you already have an array, f2, you don't need to create one. As @mfb suggests, just iterate over the array you have.
 
  • Like
Likes Erenjaeger

Similar threads

Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
20
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 24 ·
Replies
24
Views
3K