• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Simulation of sampling frequencies, but for one particular frequency the code “breaks”, maybe np.sin approximation errors?

Resolved: Simulation of sampling frequencies, but for one particular frequency the code “breaks”, maybe np.sin approximation errors?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am simulating a signal with numpy.sin in python, and i wanna simulate different sampling frequencies, the code is as follows:
The problem arises with the sampling frequency 101, here the sin function evaluates to ridiculously tiny values, something around 10^(-14) (for all the other values normal graphs come out) (Sin function Evaluated with a sampling frequency of 101 Hz) whilst if I evaluate the sine func by hand by printing out the linear array for sampling frequency 101 Hz, I get normal values. Does somebody know the problem? Maybe and approximation problem of np.sin? maybe the dtype float64 somehow breaks, because the values are kinda sus.

Answer:

When i is 101, f * linear is [0.0, 0.5, 1.0, 1.5, ...], so the expression np.sin(2 * np.pi * f * linear) is sampling the sin function at multiples of pi. If you were working with infinite precision, the values would all be 0. These sample points, however, will not be exact multiples of pi, because of normal floating point imprecision, so the values returned by that expression should be close to 0, but they won’t necessarily be exactly 0.

If you have better answer, please add a comment about this, thank you!

numpy python python-dataclasses sampling
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I implement a function depending on picked up items?

01/04/2023

Resolved: Azuer Service Bus SDK not receiving the specified messages

01/04/2023

Resolved: how to change date format from 201904 to Apr-19 in excel

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.