⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coef_seq.cpp

📁 ALTERA公司的quartusII fir_compilier-v3.31对工程师很有帮助的哦
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	{
		zeros_insert = mcv_coef_length - loc_length;
	}

	int i,j,k,l;

	k = 0;
	l = 0;
	for (i=0; i<2048; ++i)
	{
		tmp_coef[i] = 0;
	}


	k = 0;
	l = 0;

	for (i=0; i<loc_length; ++ i)
	{
		tmp_coef[i + int(zeros_insert)] = coef[i];
	}
	for (i=0; i<mcv_coef_length; ++ i)
	{
		loc_coef[i] = tmp_coef[i];
	}

	if(num_cycles > 1)
	{
			for(k = 0 ; k< num_mac; ++k)
			{
				for (i=0; i<num_cycles; ++i)
				{
					for(j = 0 ; j< poly_fact; ++j)
					{
						int tmp_index = i*poly_fact + j + k *poly_fact * num_cycles;
						int loc_index = k*poly_fact + j + i *poly_fact*num_mac;
						tmp_coef[tmp_index ] = loc_coef[loc_index];
					}
				}
			}
			for (i=0; i<mcv_coef_length; ++i)
			{
				loc_coef[i] = tmp_coef[i];
			}
			for(k = 0 ; k< num_mac; ++k)
			{
				for(j = 0 ; j< poly_fact; ++j)
				{
					for (i=0; i<num_cycles; ++i)
					{
						int tmp_index = k*poly_fact*num_cycles + i + j*num_cycles;
						int loc_index = k*poly_fact*num_cycles + i * poly_fact + j ;
						tmp_coef[tmp_index ] = loc_coef[loc_index];
					}
				}
			}
			for (i=0; i<mcv_coef_length; ++i)
			{
				loc_coef[i] = tmp_coef[i];
			}
			for(k = 0 ; k< num_mac; ++k)
			{
				for(j = 0 ; j< poly_fact; ++j)
				{
					for (i=0; i<num_cycles; ++i)
					{
						int tmp_index = k*poly_fact*num_cycles + i + j *num_cycles;
						int loc_index = k*poly_fact*num_cycles + (num_cycles -1-i) + j * num_cycles;
						tmp_coef[tmp_index ] = loc_coef[loc_index];
					}
				}
			}
	}

	for (i=0; i<mcv_coef_length; ++i)
	{
		coef[i] = tmp_coef[i];
	}
	//end of coef_resequence


	//insert zeros when use memory to store coefficient and coefficient in one memory is more than one
	int mem_num;
	int coef_one_mem = 1;
	if(coef_store_type == M512)
	{
		coef_one_mem = (int) floor(18.0/((double) coef_bit_width));
		if(coef_one_mem == 0)
		{
			coef_one_mem = 1;
		}
	}
	else if(coef_store_type == M4K)
	{
		coef_one_mem = (int) floor(36.0/((double) coef_bit_width));
	}
	else
	{
		coef_one_mem = 1;
	}
	if(coef_store_type != LC)
	{
		mem_num = (int) ceil(((double) num_mac)/ ((double)coef_one_mem));
		mcv_reload_zero_insert = mem_num * coef_one_mem - num_mac;
		if(mem_num == 1)
		{
			mcv_reload_zero_insert = 0;
		}
	}

	if(mcv_reload_zero_insert > 0)
	{
		for (j=0; j<mem_num * coef_one_mem; ++j)
		{
			for (i=0; i<calc_cycles; ++i)
			{
				if(j < (mem_num -1) * coef_one_mem)
				{
					coef[j* calc_cycles + i] = tmp_coef[j* calc_cycles + i];
				}
				else if(j <(mem_num -1) * coef_one_mem + mcv_reload_zero_insert)
				{
					coef[j* calc_cycles + i] = 0;
				}
				else
				{
					coef[j* calc_cycles + i] = tmp_coef[(j - mcv_reload_zero_insert)* calc_cycles + i];
				}
			}
		}
	}

}

void single_rate_out_write()
{
/**********************************************************************************
*
* Write coeficients to file
* Single-Rate Filter
*	
**********************************************************************************/
	ofstream out_file;
	int i,j,k,m,l;
	int jg;
	int index_cnt;
	int sub_coef[30];
	int size;
	int tmp_coef[2048];
	char temp[32];
	char bi_index[256];
	int mcv_coef_length = (num_mac + mcv_reload_zero_insert) * num_cycles;
	
	out_file.open(out_name, ios::out);
	i = out_file.is_open();
	if (i!=0)
	{
		if(struct_type == MCV)
		{
			out_file <<  coef[0] ;	
			for (i=1; i<mcv_coef_length; ++i)
			{
				out_file << "\n"<< coef[i] ;	
			}
		}
		else
		{
			for (jg=0; jg<num_coef_group; ++jg)                                             
			{ 
				for( k = 0; k < group_size; ++ k)
				{
					index_cnt = jg * group_size + k;
					if(index_cnt < coef_length)                                              
					{                                                                  
						sub_coef[k] = coef[index_cnt];                      
					}
					else
					{
						sub_coef[k] = 0;
					}
				}
				size = (int) pow(2.0, group_size);                                               
                                                                          
				int conv_value = (int)pow(2.0, mem_width);                                        
				for(m=0; m< size; m++)                                                     
				{                                                                          
					tmp_coef[0]  = 0;
					itobi(temp, m);//integer to binary                                
					strcpy(bi_index, temp);                                            
					j= strlen(bi_index);                                               
					for(l = 0; l<j; ++l)                                               
					{                                                                  
						if(bi_index[l] == 49)                                      
						{                                                          
							tmp_coef[0] = tmp_coef[0]  + sub_coef[j-1-l];       
						}                                                          
					}                                                                  
					if(tmp_coef[0]  < 0)                                                
					{                                                                  
						tmp_coef[0]  = conv_value + tmp_coef[0] ;                    
					}
					if(jg == 0 && m == 0)
					{
						out_file << "0";
					}
					else
					{
						out_file << "\n"<< tmp_coef[0] ;
					}
				}  
			}                                                                          
		}
	}
	out_file.close();
}
void multi_rate_poly_out_write()
{
/**********************************************************************************
*
* Write coeficients to file
* Multi-Rate Filter
// Maybe creating a 2-D array of coeficients would be a better option
// run the writer section one phase after another concatenating the ouptut
// from each run to form the loadable PP set
*
**********************************************************************************/
	ofstream out_file;
//	ofstream temp_file;
	int i,j,k,m,l;
	int coef_mr_arr[128][16];
	int jg;
	int index_cnt;
	int sub_coef[30];
	int size;
	int tmp_coef[2048];
	char temp[32];
	char bi_index[256];


	if(poly_type==INT||poly_type==DEC)
	{
		out_file.open(out_name, ios::out);
//		temp_file.open("c:/cvs/sj/projects/fir_compiler/work/gui/temp/coef_arr.txt", ios::out);
		i = out_file.is_open();
		if (i!=0)
		{
			if(struct_type == MCV)
			{
				out_file <<  coef[0] ;	
				for (i=1; i<poly_fact*length_wr; ++i)
				{
					out_file << "\n"<< coef[i] ;	
				}
			}
			else
			{
			// Initialize 2-D array of coeficients coef_mr_arr[16][2048]
				for(i = 0; i < 16; ++i)
				{
					for (j = 0; j < 128; ++j)
					{	
						coef_mr_arr[j][i] = 0;
					}
				}
				// Generate 2-D array of coeficients coef_mr_arr[phase][j]
				for(i = 0; i < poly_fact; ++i)
				{
					for (j = 0; j < length_wr; ++j)
					{	
						coef_mr_arr[j][i] = coef[j*poly_fact+i];
					}
				}
				for(i = 0; i < poly_fact; ++i)
				{
					for (jg=0; jg<num_coef_group; ++jg)                                             
					{ 
						for( k = 0; k < group_size; ++ k)
						{
							index_cnt = jg * group_size + k;
							if(index_cnt < coef_length)                                              
							{                                                                  
								sub_coef[k] = coef_mr_arr[index_cnt][i];                      
							}
							else
							{
								sub_coef[k] = 0;
							}
						}
						size = (int)pow(2.0, group_size);                                               
                                                                                                  
						int conv_value = (int)pow(2.0, mem_width);                                        
						for(m=0; m< size; m++)                                                     
						{                                                                          
							tmp_coef[0]  = 0;
							itobi(temp, m);//integer to binary                                
							strcpy(bi_index, temp);                                            
							j= strlen(bi_index);                                               
							for(l = 0; l<j; ++l)                                               
							{                                                                  
								if(bi_index[l] == 49)                                      
								{                                                          
									tmp_coef[0] = tmp_coef[0]  + sub_coef[j-1-l];       
								}                                                          
							}                                                                  
							if(tmp_coef[0]  < 0)                                                
							{                                                                  
								tmp_coef[0]  = conv_value + tmp_coef[0] ;                    
							}
							if(jg == 0 && m == 0)
							{
								out_file << "0";
							}
							else
							{
								out_file << "\n"<< tmp_coef[0] ;
							}
						}  
					}                                                                          
				out_file << "\n";
				}
				//out_file << "\n";
			}
		}
		out_file.close();
//		temp_file.close();
		//printf("num_coef_group=%d group_size =%d size=%d\n",num_coef_group,group_size,size);
	}

}
void deci_out_write()
{
	ofstream out_file;
	out_file.open(out_name, ios::out);
	int index_adjust = 0;
	int i,k,j;
	int calc_cycles = num_cycles;

    if(poly_type == DEC)
	{
		calc_cycles = num_cycles * poly_fact;
	}
	
	if(coef_store_type == LC)
	{
		for(i=num_mac -1; i>= 0; --i)
		{
			for (k=calc_cycles -1; k>= 0; --k)
			{
				
/*				if(num_cycles == 1)
				{
					index_adjust = k + 2;
				}
				else
				{
					index_adjust = k;
				}
				if(sym == 0 && num_cycles == 1)
				{
//					index_adjust--;
					index_adjust = k +3 - poly_fact;
				}*/


				index_adjust = k + 4;
				if(sym != 0)
				{
					index_adjust++;
				}
				if(num_coef_set > 1)
				{
					index_adjust--;
				}


				while( index_adjust >= calc_cycles)
				{
					index_adjust = index_adjust - calc_cycles;
				}
				while( index_adjust < 0 )
				{
					index_adjust = index_adjust + calc_cycles;
				}

				j = coef[i * calc_cycles + index_adjust];
				out_file << j <<"\n"; ;
			}
		}
	}
	else
	{
		for (k=0; k<calc_cycles; ++k)
		{
			for(i=0; i<num_mac + mcv_reload_zero_insert; ++i)
			{
				j = coef[i * calc_cycles + k];
				out_file << j <<"\n"; ;
			}
		}

	}
	out_file.close();
}

void itobi(char str_deci[32], int i)
{
	char str_temp[32];

	str_deci[0] = '\0';
	int med;
	while (i > 0)
	{
		str_temp[0] = '\0';
		int j= strlen(str_temp);
		med = (i >> 1);
		if ( i == (med << 1) )
		{strcat(str_temp,"0");}
		else
		{strcat(str_temp,"1");}
		i = med;
		strcat(str_temp,str_deci);
		strcpy(str_deci,str_temp);
	}
}

                                                                                       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -