 Tags IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 # Is there a way to generate Square-Like Wave using Time Series data in Matplotlib?

By : Zelalem Senbetu
Date : October 17 2020, 06:10 AM
I wish did fix the issue. Use np.clip as: code :
``````x=[12, 34, 97, -4, -100, -9, 31, 87, -5, -2, 33, 13, 1]
np.clip(x, a_min=-1, a_max=1)

array([ 1,  1,  1, -1, -1, -1,  1,  1, -1, -1,  1,  1,  1])
``````
``````s = pd.Series(x)
s = s.clip(lower=-1, upper=1)
``````
``````x = np.where(np.array(x)>0, 1, -1) # for series s = np.where(s>0, 1, -1)
``````
``````print(s)
0     1
1     1
2     1
3    -1
4    -1
5    -1
6     1
7     1
8    -1
9    -1
10    1
11    1
12    1
dtype: int64
``````

## How to generate a square wave using C#?

By : user3427274
Date : March 29 2020, 07:55 AM
hope this fix your issue The easiest way I can think of is to set y to be sign of a sine wave, making allowances for when it equals zero. I don't know if C# has the triple-operator, but something like this might work:
code :
``````y[k] = Math.Sin(freq * k)>=0?A:-1*A;
``````

## How do you generate a square wave using two inputs in labview?

By : Stefano Peduzzi
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Your math is off, you should calculate the 2 ms as a percentage of the pulse frequency. So with 50 Hz (or 20 ms) your duty cycle is 10%.

## Create a sine wave from time series data (Python)

By : Ryan Chew Guan Rong
Date : March 29 2020, 07:55 AM
wish help you to fix your issue The current dataset that you show indeed looks nothing like a sine-wave but since all mathematically nice functions can be written as a superposition of sines and cosines, this need not be a problem.
More details in the docs: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.fft.fft.html#numpy.fft.fft
code :
``````import numpy as np
import matplotlib.pyplot as plt
T = 100
x = np.arange(0,T)
y=  np.sin(4*np.pi*x/T)+np.cos(8*np.pi*x/T)
``````
``````sp   = np.fft.fft(y)               # the discrete fourier transform
freq = np.fft.fftfreq(y.shape[-1]) # the accompanying frequencies
``````
``````cos=np.sum([(sp[-i]+sp[i]).real/(2*T)*np.cos(2.*np.pi*freq[i]*x)\
for i in range(len(freq))],axis=0)
sin=np.sum([(sp[-i]-sp[i]).imag/200.*np.sin(2.*np.pi*freq[i]*x)\
for i in range(len(freq))],axis=0)

plt.plot(x, y,x,cos+sin)
plt.show()
``````
``````T=9
x=np.arange(0,T,0.01) # the interspacing of the datpoints for the (co)sines is 0.01
y = np.array([1,0,0,0,0,0,0,1,0]) # the input data you suggested
sp = np.fft.fft(y)
freq = np.fft.fftfreq(y.shape[-1])
cos=np.sum([(sp[-i]+sp[i]).real/(2*T)*np.cos(2.*np.pi*freq[i]*x)\
for i in range(len(freq))],axis=0)
sin=np.sum([(sp[-i]-sp[i]).imag/200.*np.sin(2.*np.pi*freq[i]*x)\
for i in range(len(freq))],axis=0)

plt.plot(np.arange(0,9), y,x,cos+sin)
plt.show()
``````

## How can I generate a square wave plot of a pulse train of multiple signals from the data in a csv file (in Linux)?

By : user3665115
Date : March 29 2020, 07:55 AM
Hope that helps For instance, given the data in a text file: , The answer I ended up with was:
code :
``````    file_info = os.stat( self.__outfile)
if file_info.st_size:
x,y,z,a = np.genfromtxt( self.__outfile, delimiter=',',unpack=True )
fig = plt.figure(self.__outfile)
fig.canvas.draw()

test_array = [(datetime.datetime.utcfromtimestamp(e2).strftime('%d_%H:%M:%S.%f')).rstrip('0') for e2 in x]
plt.xticks(x, test_array)
l1, = plt.plot(x,y, drawstyle='steps-post')
l2, = plt.plot(x,a-2, drawstyle='steps-post')
l3, = plt.plot(x,z-4, drawstyle='steps-post')

ax.grid()
ax.set_xlabel('Time (s)')
ax.set_ylabel('HIGH/LOW')
ax.set_ylim((-6.5,1.5))
ax.set_title('Sensor Sequence')
fig.autofmt_xdate()
ax.legend([l1,l2, l3],['sprinkler','lights', 'alarm'], loc='lower left')
plt.show()
``````

## How can I get a square wave by using python pandas or matplotlib？

By : Tuan Anh
Date : March 29 2020, 07:55 AM
I wish this helpful for you One option is to simply set the linestyle of the plots to be "steps" using the linestyle= argument of df.plot():
code :
``````df.plot(x='StartDateTime', y=['UCL','LCL','P-bar','P'], linestyle='steps')
`````` 