0

I want to use cos() function in my code to make my own signal source, but i don't know how to get the output with both the quadrature phase too EXACTLY like what a built-in signal source outputs.

Can anyone please help me with the python code to make a signal source using Python Module in flow graph.

DETAILS:

The code i wrote is:

def work(self, input_items, output_items):
fs_local = 30e6;
for i in range(0, fs_local):
  output_items[0][i]=  math.cos(2*pi*(math.pi)/fs_local)
return len(output_items[0])

The problem is that output items length is perhaps by default fixed to be 4096. so any range in for loop not equal to output_items(i.e. for i in range(0, len(output_items[0]) or input_items(disabled in my case) is not going to work and does not show any output. And if i use output_items length exactly as i wrote in above paragraph, then it will truncate the range to 4096 and thus outputs a ramp which is not my desired output.

Similarly not returning "len(output_items[0])" and instead returning "len(fs_local) won't show any results either.

Also how to output a 90 degree shifted cos wave too along with correctly outputting the cosine wave itself just like a built-in signal source?

Khan
  • 23
  • 1
  • 7
  • 1
    we don't know where you're stuck, and we surely won't write a complete block that does what you need it to do. Please add your code, and tell us how it differs from what the reference source outputs. Questions of the type "my code is not working" must **include** that code, as well as sufficient attempt to diagnose and solve. – Marcus Müller May 03 '19 at 19:44
  • I have just edited.Thank you for indicating. – Khan May 04 '19 at 07:14
  • That is not even legal in Python! You can't have a floating point upper limit for `range`. Please post your **actual** code. Also, it doesn't work like this: you have a limited amount of space in `output_items`, but you just write 30 millions (definitely more than you'd ever have space). So, you're either not even trying to run this code, or ignoring the error messages! – Marcus Müller May 04 '19 at 10:50
  • The code i showed does contain errors, and of course that is my problem, i want to visualize cosine wave of 30e6Hz through my code just the same way a built-in block outputs, but using the cos() seems not to serve the purpose, because range becomes an issue. Is there any Built-in command that should be used instead? Thanks for your concern though – Khan May 04 '19 at 16:13
  • your code is not even valid Python, so trying to figure out how to solve your signal processing problems is a bit too early. You need to understand how to write Python first, and how to read the error messages you're **still ignoring**. – Marcus Müller May 04 '19 at 16:19
  • I am finally able to do this the following way: for i in range(0,len(output_items[0])-1): output_items[0][i]= math.sin(2*3.14*(i)/4096) return len(output_items[0]) But now i am stuck because i want to output wave with frequency 30e6 so how can i output frequency of 30e6 on the page size 4096 and the same time axis duration as that of built-in signal source? – Khan May 13 '19 at 21:54

0 Answers0