2017-04-19 16 views
-1

나는의 Microsoft Visual C++ 2010 (32 비트 시스템)에서 일한지가C++ 오류 : ". 윈도우 Espectrogramafrequencia.exe에 중단 점을 트리거하고있다"

컴파일 단계 괜찮아,하지만 실행에 나는 얻을

"Espectrogramafrequencia.exe에서 Windows가 중단 점을 트리거했습니다.이 오류는 Espectrogramafrequencia.exe 또는로드 한 DLL의 버그를 나타내는 힙 손상으로 인한 것일 수 있습니다. Espectrogramafrequencia.exe에 포커스가있을 때 사용자가 F12 키를 눌러야합니다. 출력 창에 진단 정보가 더있을 수 있습니다. [계속] [무시] "

코드 :

#include "StdAfx.h" 
#include <stdlib.h> 
#include <stdio.h> 
#include <time.h> 
#include <fftw3.h> 
#include <iostream> 
#include <cmath> 
#include <fstream> 

using namespace std; 

int main() 
{ 
int i; 
const int N=550;//Number of points acquired inside the window 
double Fs=200;//sampling frequency 
double dF=Fs/N; 
double T=1/Fs;//sample time 
double f=50;//frequency 
double *in; 
fftw_complex *out; 
double t[N];//time vector 
double ff[N]; 
fftw_plan plan_forward; 
in = (double*) fftw_malloc(sizeof(double) * N); 
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); 
for (int i=0; i<= N;i++) 
{ 
t[i]=i*T; 
double M_PI=3.14159265359; 
in[i] =0.7 *sin(2*M_PI*f*t[i]);// generate sine waveform 
double multiplier = 0.5 * (1 - cos(2*M_PI*i/(N-1)));//Hanning Window 
in[i] = multiplier * in[i]; 
} 
for (int i=0; i<= ((N/2)-1);i++){ 
ff[i]=Fs*i/N;} 
plan_forward = fftw_plan_dft_r2c_1d (N, in, out, FFTW_ESTIMATE); 
fftw_execute (plan_forward); 
double v[N]; 
for (int i = 0; i<= ((N/2)-1); i++){ 
v[i]=(20*log(sqrt(out[i][0]*out[i][0]+ out[i][1]*out[i][1])))/N; //Here I have calculated the y axis of the spectrum in dB 
} 
fstream fichero; 
fichero.open("example2.txt",fstream::out);//fichero.open("example2.txt"); 
fichero << "plot '-' using 1:2" << std::endl;//fichero << "plot '-' using 1:2" << endl; 
for(i = 0;i< ((N/2)-1); i++){ 
fichero << ff[i]<< " " << v[i]<< std::endl; 
} 
fichero.close(); 
fftw_destroy_plan (plan_forward); 
fftw_free (in); 
fftw_free (out); 
return 0; 
} 

당신이 오류가 무엇을 의미하는지 어떤 생각이 있나요? "힙의 손상"은 무엇을 의미합니까?

도와주세요

정말 고마워요!

+3

:
는 같은 for 루프를 사용합니다. 색인 생성을보십시오. – molbdnilo

+3

for (int i = 0; i <= N; i ++)의 루프 색인 생성은 의심스러운 작업입니다. 즉'N + 1 '번 반복 할 것이라는 것을 의미합니다. 이는 N 개의 블록을 다루는 경우 나쁜 소식입니다. –

+0

감사합니다. Phil Brubaker –

답변

1

t[] 메모리 제한을 벗어나는 값을 할당하려고합니다.
C++ 배열은 0부터 시작하는 인덱스이므로 배열 t[]의 인덱스 범위는 0..549입니다. 당신은 동적으로 할당 된 무언가의 주변에, 당신이 아니었다 일부 메모리를 수정 한

for (int i=0; i< N;i++)