【发布时间】:2018-09-21 07:29:50
【问题描述】:
我正在尝试实现这个
Fs = 2000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 4000; % Length of signal
t = (0:L-1)*T; %time samples
A=[16 18 28 33 38 41 59 43 40 58];% Amplitude of noise in dBA (refer to the measurements from consultant)
forigin=[25 31.5 40 50 63 80 100 125 160 200];% Frequency of the noise components (refer to the measurements from consultant)
S=zeros(1,length(t));% This will be the signal representing transformer noise, in your case, it will be the sound created from exciter
%V=zeros(1,L);%not needed, you can remove this
for k=1:length(A)
S = S+10^(A(k)/20)*sin(2*pi*forigin(k)*t);%Creating the transformer noise from the amplitude and frequency components, in your case, it will be the sound created from exciter
end
到目前为止,我已经得到了这个,似乎 k 没有通过 forigin 数组递增。
#define _USE_MATH_DEFINES // to force M_PI to exist
#include <math.h> //for pow, sin and M_PI
#define ASIZE 10 //for A
#define TSIZE 40 //or 4000
int Fs = 2000;
int L = 40;
double A[ASIZE] = {16, 18, 28, 33, 38, 41, 59, 43, 40, 58};
double forigin[ASIZE] = {25.0, 31.5, 40.0, 50.0, 63.0, 80.0, 100.0, 125.0, 160.0, 200.0};
double S[TSIZE];
double t[TSIZE];
double T = 1/(double)Fs;
int i,k, j;
//int k = 10;
double apow = pow(10, A[k]/20);
void setup() {
Serial.begin(9600);
}
void loop()
{
for ( i = 0; i < TSIZE ; i++ ) /* initialize elements of array t to 0 */
{
t[i] = (double) i*T; /* set element at location i to i*T */
}
for (j = 0; j < TSIZE; j++ ) /* output each array element's value */
{
// Serial.print(t[j],15);
// Serial.println("");
// delay(500);
}
//initialise S to 0
for (i = 0; i < TSIZE; ++i) //S[i] = 0;
//implement the for k=1:length(A)
for (k = 0; i < ASIZE; ++k){
//devectorise the S calculation
for (i = 0; i < TSIZE; ++i){
S[i] = S[i] + pow(10, A[k]/20) * sin(2*M_PI*forigin[k]*t[i]);
Serial.print(S[i]);
Serial.println("");
delay(500);
有人可以帮忙吗? Matlab已经推出了
matlab中的实际S值是 0 899.475071494380 1570.91017541897 1861.36356724185 1740.88440906200 1306.16803613629 739.441548916790 238.639601470524 -54.6370978848435 -102.514143930475
如你所见,我没有得到这样的东西。
【问题讨论】:
标签: arrays matlab for-loop multidimensional-array