I have a very little approach with coding in C# in asp.net please help converting this python code into c#.

# Python example - Fourier transform using numpy.fft method

import numpy as np

import matplotlib.pyplot as plotter



# How many time points are needed i,e., Sampling Frequency

samplingFrequency   = 100;



# At what intervals time points are sampled

samplingInterval       = 1 / samplingFrequency;



# Begin time period of the signals

beginTime           = 0;



# End time period of the signals

endTime             = 10; 



# Frequency of the signals

signal1Frequency     = 4;

signal2Frequency     = 7;



# Time points

time        = np.arange(beginTime, endTime, samplingInterval);



# Create two sine waves

amplitude1 = np.sin(2*np.pi*signal1Frequency*time)

amplitude2 = np.sin(2*np.pi*signal2Frequency*time)



# Create subplot

figure, axis = plotter.subplots(4, 1)

plotter.subplots_adjust(hspace=1)



# Time domain representation for sine wave 1

axis[0].set_title('Sine wave with a frequency of 4 Hz')

axis[0].plot(time, amplitude1)

axis[0].set_xlabel('Time')

axis[0].set_ylabel('Amplitude')





# Time domain representation for sine wave 2

axis[1].set_title('Sine wave with a frequency of 7 Hz')

axis[1].plot(time, amplitude2)

axis[1].set_xlabel('Time')

axis[1].set_ylabel('Amplitude')



# Add the sine waves

amplitude = amplitude1 + amplitude2



# Time domain representation of the resultant sine wave

axis[2].set_title('Sine wave with multiple frequencies')

axis[2].plot(time, amplitude)

axis[2].set_xlabel('Time')

axis[2].set_ylabel('Amplitude')



# Frequency domain representation

fourierTransform = np.fft.fft(amplitude)/len(amplitude)           # Normalize amplitude

fourierTransform = fourierTransform[range(int(len(amplitude)/2))] # Exclude sampling frequency



tpCount     = len(amplitude)

values      = np.arange(int(tpCount/2))

timePeriod  = tpCount/samplingFrequency

frequencies = values/timePeriod



# Frequency domain representation

axis[3].set_title('Fourier transform depicting the frequency components')



axis[3].plot(frequencies, abs(fourierTransform))

axis[3].set_xlabel('Frequency')

axis[3].set_ylabel('Amplitude')



plotter.show()

Please correct those code submissions. All those extra blank lines distract and show not much care here.

My background does include DSP work which had FFT in various languages but your lack of care has me not write much more than about your code so far.

Also, your program's goals are untold. I see more than a FFT here with what looks to be graphical output. That is a lot more work as for "C" we'd have to pick our graphics library and more. There is no easy conversion. Maybe if we moved to C# or such but hey, you didn't tell enough to start discussing possible development ideas.

commented: I'm sorry about the extra blank spaces however the basic requirement of this code is to read the data from excel sheet calculate FFT and plot graph. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.