我正在使用C++/C对某些数据执行前向和反向FFT,这些数据应该是激光器的脉冲输出.
我们的想法是获取输出,使用正向FFT转换到频域,对相位应用线性最佳拟合(首先展开它),然后从相位信息中减去这个最佳拟合.
然后将得到的相位和幅度转换回时域,最终目标是通过相位补偿压缩脉冲.
我试图在MATLAB中不成功地做到这一点,结果转而使用C++.前向FFT工作正常,我从C++中的数字配方中获取了基本配方,并使用函数对复杂输入进行修改,如下所示:
void fft(Complex* DataIn, Complex* DataOut, int fftSize, int InverseTransform, int fftShift)
{
double* Data = new double[2*fftSize+3];
Data[0] == 0.0;
for(int i=0; i<fftSize; i++)
{
Data[i*2+1] = real(DataIn[i]);
Data[i*2+2] = imag(DataIn[i]);
}
fft_basic(Data, fftSize, InverseTransform);
for(int i=0; i<fftSize; i++)
{
DataOut[i] = Complex(Data[2*i+1], Data[2*i+2]);
}
//Swap the fft halfes
if(fftShift==1)
{
Complex* temp = new Complex[fftSize];
for(int i=0; i<fftSize/2; i++)
{
temp[i+fftSize/2] = DataOut[i];
}
for(int i=fftSize/2; i<fftSize; i++)
{
temp[i-fftSize/2] = DataOut[i];
}
for(int i=0; …Run Code Online (Sandbox Code Playgroud) 我很确定我的代码是正确的,但它似乎没有返回预期的输出:
输入anti_vowel("Hey look words") - >输出:"Hey lk wrds".
显然它不起作用'e',任何人都可以解释为什么?
def anti_vowel(c):
newstr = ""
vowels = ('a', 'e', 'i', 'o', 'u')
for x in c.lower():
if x in vowels:
newstr = c.replace(x, "")
return newstr
Run Code Online (Sandbox Code Playgroud) 所以我刚刚完成了CodeAcademy Battleship问题的一部分,并提交了正确的答案,但我很难理解为什么它是正确的.
我们的想法是建立一个5x5网格作为板,填充"O".我使用的正确代码是:
board = []
board_size=5
for i in range(board_size):
board.append(["O"] *5)
Run Code Online (Sandbox Code Playgroud)
但是我很困惑为什么这不会在一行中创建25个"O",因为我从未指定迭代到单独的行.我试过了
for i in range(board_size):
board[i].append(["O"] *5)
Run Code Online (Sandbox Code Playgroud)
但这给了我错误:IndexError: list index out of range.任何人都可以解释为什么第一个是正确的而不是第二个?
我很难在图中打开和关闭轴,以及适当调整轴的大小。我遵循了几个线程,我的方法是:
f1=plt.figure(1,(3,3))
ax=Subplot(f1,111)
f1.add_subplot(ax)
ax.scatter(current,backg,label='Background Height')
ax.plot(current,backg)
ax.scatter(current,peak,color = 'red',label='Peak Spot Height')
ax.plot(current,peak,color='red')
ax.plot(current,meanspot,color='green')
ax.scatter(current,meanspot,color = 'green',label='Mean Spot Height')
ax.spines['left'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('center')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
Run Code Online (Sandbox Code Playgroud)
但是我的图形仍然在顶部和右侧带有轴,并且由于轴的大小而出现奇怪的间隙。
我正在使用行进立方体算法的Scikit Image实现来生成等值面。
verts, faces,normals,values = measure.marching_cubes(stack,0)
Run Code Online (Sandbox Code Playgroud)
产生以下错误:
ValueError:需要两个以上的值才能解压
但
verts, faces = measure.marching_cubes(stack,0)
Run Code Online (Sandbox Code Playgroud)
如此看来算法根本就没有产生的值正常工作normals和values。有没有人有过这类问题的经验?
此外,我不了解faces算法输出的必要性,因为网格中每个三角形的一组3个顶点应该足以描述等值面?