📄 slmsolver.c
字号:
/*
* File: SLMsolver.c
*
*
*
* --- THIS FILE GENERATED BY S-FUNCTION BUILDER: 2.0 ---
*
* This file is an S-function produced by the S-Function
* Builder which only recognizes certain fields. Changes made
* outside these fields will be lost the next time the block is
* used to load, edit, and resave this file. This file will be overwritten
* by the S-function Builder block. If you want to edit this file by hand,
* you must change it only in the area defined as:
*
* %%%-SFUNWIZ_defines_Changes_BEGIN
* #define NAME 'replacement text'
* %%% SFUNWIZ_defines_Changes_END
*
* DO NOT change NAME--Change the 'replacement text' only.
*
* For better compatibility with the Real-Time Workshop, the
* "wrapper" S-function technique is used. This is discussed
* in the Real-Time Workshop User's Manual in the Chapter titled,
* "Wrapper S-functions".
*
* -------------------------------------------------------------------------
* | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
* -------------------------------------------------------------------------
* Created: Sun May 1 01:06:11 2005
*
*
*/
#define S_FUNCTION_NAME SLMsolver
#define S_FUNCTION_LEVEL 2
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/* %%%-SFUNWIZ_defines_Changes_BEGIN --- EDIT HERE TO _END */
#define NUM_INPUTS 4
/* Input Port 0 */
#define IN_PORT_0_NAME block0
#define INPUT_0_WIDTH -1
#define INPUT_DIMS_0_COL 1
#define INPUT_0_DTYPE creal_T
#define INPUT_0_COMPLEX COMPLEX_YES
#define IN_0_FRAME_BASED FRAME_YES
#define IN_0_DIMS 1-D
#define INPUT_0_FEEDTHROUGH 1
/* Input Port 1 */
#define IN_PORT_1_NAME block1
#define INPUT_1_WIDTH -1
#define INPUT_DIMS_1_COL 1
#define INPUT_1_DTYPE creal_T
#define INPUT_1_COMPLEX COMPLEX_YES
#define IN_1_FRAME_BASED FRAME_YES
#define IN_1_DIMS 1-D
#define INPUT_1_FEEDTHROUGH 1
/* Input Port 2 */
#define IN_PORT_2_NAME block2
#define INPUT_2_WIDTH -1
#define INPUT_DIMS_2_COL 1
#define INPUT_2_DTYPE creal_T
#define INPUT_2_COMPLEX COMPLEX_YES
#define IN_2_FRAME_BASED FRAME_YES
#define IN_2_DIMS 1-D
#define INPUT_2_FEEDTHROUGH 1
/* Input Port 3 */
#define IN_PORT_3_NAME block3
#define INPUT_3_WIDTH -1
#define INPUT_DIMS_3_COL 1
#define INPUT_3_DTYPE creal_T
#define INPUT_3_COMPLEX COMPLEX_YES
#define IN_3_FRAME_BASED FRAME_YES
#define IN_3_DIMS 1-D
#define INPUT_3_FEEDTHROUGH 1
#define NUM_OUTPUTS 1
/* Output Port 0 */
#define OUT_PORT_0_NAME phase
#define OUTPUT_0_WIDTH 4
#define OUTPUT_DIMS_0_COL 1
#define OUTPUT_0_DTYPE creal_T
#define OUTPUT_0_COMPLEX COMPLEX_YES
#define OUT_0_FRAME_BASED FRAME_YES
#define OUT_0_DIMS 1-D
#define NPARAMS 0
#define SAMPLE_TIME_0 INHERITED_SAMPLE_TIME
#define NUM_DISC_STATES 0
#define DISC_STATES_IC [0]
#define NUM_CONT_STATES 0
#define CONT_STATES_IC [0]
#define SFUNWIZ_GENERATE_TLC 0
#define SOURCEFILES ""
#define PANELINDEX 6
#define SFUNWIZ_REVISION 2.0
/* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "simstruc.h"
#include <malloc.h>
#include <memory.h>
#include <iostream.h>
/*
* Include Files
*
*/
#include "tmwtypes.h"
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#include <math.h>
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1
#define y_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Output functions
*
*/
void SLMsolver_Outputs_wrapper(SimStruct *Ss, const creal_T *block0,
const creal_T *block1,
const creal_T *block2,
const creal_T *block3,
creal_T *phase)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
/* This sample sets the output equal to the input
y0[0] = u0[0];
For complex signals use: y0[0].re = u0[0].re;
y0[0].im = u0[0].im;
y1[0].re = u1[0].re;
y1[0].im = u1[0].im;*/
int_T p0,p1,p2,p3,i;
int_T max_p0, max_p1,max_p2,max_p3 ;
real_T min_PAR, cos_p0,sin_p0, cos_p1,sin_p1, cos_p2,sin_p2,cos_p3,sin_p3 ;
real_T sum_energy, max_power ;
int_T data_width = ssGetInputPortWidth(Ss,0) ;
creal_T* S =(creal_T*)malloc(data_width*sizeof(creal_T)) ;
min_PAR = 1.0e15 ;
max_p0 = 0 ;
max_p1 = 0 ;
max_p2 = 0 ;
max_p3 = 0 ;
for ( p0 = 0 ; p0 < 4 ; p0++ )
{
for ( p1 = 0 ; p1 < 4 ; p1++ )
{
for ( p2 = 0 ; p2 < 4 ; p2++ )
{
for ( p3 = 0 ; p3 < 4 ; p3++ )
{
sum_energy = 0;
max_power = 0;
for ( i = 0 ; i < data_width ; i++ )
{
cos_p0 = cos(3.1416*(2*p0+1)/4) ;
sin_p0 = sin(3.1416*(2*p0+1)/4) ;
cos_p1 = cos(3.1416*(2*p1+1)/4) ;
sin_p1 = sin(3.1416*(2*p1+1)/4) ;
cos_p2 = cos(3.1416*(2*p2+1)/4) ;
sin_p2 = sin(3.1416*(2*p2+1)/4) ;
cos_p3 = cos(3.1416*(2*p3+1)/4) ;
sin_p3 = sin(3.1416*(2*p3+1)/4) ;
S[i].re = block0[i].re * cos_p0 - block0[i].im * sin_p0 +
block1[i].re * cos_p1 - block1[i].im * sin_p1 +
block2[i].re * cos_p2 - block2[i].im * sin_p2 +
block3[i].re * cos_p3 - block3[i].im * sin_p3 ;
S[i].im = block0[i].im * cos_p0 + block0[i].re * sin_p0 +
block1[i].im * cos_p1 + block1[i].re * sin_p1 +
block2[i].im * cos_p2 + block2[i].re * sin_p2 +
block3[i].im * cos_p3 + block2[i].re * sin_p3 ;
sum_energy = sum_energy + S[i].re * S[i].re + S[i].im * S[i].im ;
if (max_power<=(S[i].re * S[i].re + S[i].im * S[i].im))
max_power = S[i].re * S[i].re + S[i].im * S[i].im ;
}
if (min_PAR >= (data_width * max_power/sum_energy))
{
min_PAR = (data_width * max_power/sum_energy) ;
max_p0 = p0 ;
max_p1 = p1 ;
max_p2 = p2 ;
max_p3 = p3 ;
}
}
}
}
}
phase[0].re = max_p0 ;
phase[0].im = 0 ;
phase[1].re = max_p1 ;
phase[1].im = 0 ;
phase[2].re = max_p2 ;
phase[2].im = 0 ;
phase[3].re = max_p3 ;
phase[3].im = 0 ;
free(S);
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Updates function
*
*/
void SLMsolver_Update_wrapper(const creal_T *block0,
const creal_T *block1,
const creal_T *block2,
const creal_T *block3,
const creal_T *phase )
{
/* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */
/*
* Code example
* xD[0] = u0[0];
*/
/* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -