如何在matlab中生成具有纹波的正弦信号?

时间:2016-07-12 08:49:45

标签: matlab

我需要一个频率为50 Hz,幅度为50的正弦波。此外,我需要一个三角波纹(+10到-10)和一个1000 Hz的频率沿着正弦波,如下所示< / p>

example image

平均值是正弦波,但实际波形不是波纹(即以三角形形式脉动)。原始波形是三角形传播(移动)形式的正弦波

`

f_inv_ac = 50; 

fs_inv = 1e3;

p_inv_ac = 150e3;  % power in Watt

u_inv_ac_rms = 400; % output voltage (RMS) in V

i_inv_ac_rms = p_inv_ac/u_inv_ac_rms/sqrt(3);

t_inv_ac = 1/f_inv_ac; % Inverter output period in s

ts_inv = 1/fs_inv; % Inverter switching period in s

vector_calc = zeros(1, num_inv_switch);

t_inv = vector_calc;

angle_inv_rn  = vector_calc;


for i = 1:num_inv_switch

    t_inv(i) = i*ts_inv;

    angle_inv_rn(i) = 2*pi*t_inv(i)/t_inv_ac;

end


u_inv_ac_rn = u_inv_ac_rms*sqrt(2/3)*sin(angle_inv_rn); % R-N voltage

i_inv_ac_r = i_inv_ac_rms*sqrt(2)*sin(angle_inv_rn); % R current

figure 

plot(t_inv*1e3,i_inv_ac_r)


%% for ripple calulation

 fs_inv = 1e3; % frequency ripple

% current ripple

delta_i_inv_r = zeros(1, num_inv_switch);

% current peak-value

i_peak_inv_r = zeros(1, num_inv_switch);

% current bottom-value

i_bottom_inv_r = zeros(1, num_inv_switch);

 % Current ripple (peak-to-peak) (in version 1.00 no ripple considered)

    delta_i_inv_r(i) = i_inv_ac_r(i)*0.30;


 % Current-peak value

 i_peak_inv_r(i) = i_inv_ac_r(i) + delta_i_inv_r(i)/2;

 i_bottom_inv_r(i) = i_inv_ac_r(i) - delta_i_inv_r(i)/2;`

我不知道接下来该怎么办。

2 个答案:

答案 0 :(得分:2)

我将在不使用您的代码的情况下解决问题,我希望您不会被冒犯,但很难理解您的所有变量,而且您的某些变量也丢失了,我无法运行您的代码:

首先让我们创建一个范围:

t = 0:0.00001:0.1; %test range - change 0.00001 to get more samples.
y=50*sin(2*pi*50*t); %generated simple Sine wave
% generate Triangle wave
period=1/2000; % same as 1/frequency in your case, 2000Hz
phase=0; % 0 unless you want it phase shifted
ratio=0.5; % 50:50 ratio, if you want sawtooth use 0.99
amp=20*1.25; %generates the 0 to 20 range for triangle wave
u1=rem(t+phase*period/(2*pi)+period,period);
s=(u1<=period*ratio).*u1*amp/(period*ratio)+(u1>period*ratio).*(period-u1)*amp/(period*(1-ratio))-10; %NOTE this is actually Simulink's triangle wave generator

%combine them
z = s+y;

figure
plot(t,y,'r')
hold on
plot(t,z)

and there you have it

答案 1 :(得分:0)

我认为在你的情况下你想要试验sawtooth的频率和振幅。

amplitude=1;
amplitude2=0.1;
amplitude3=0.3;
t=1:0.01:10;
frequency=0.1;
frequency2=1;
frequency3=4;
sinusoid = amplitude * (sin(frequency * 2 * pi * t));

sinusoid2 = sinusoid + amplitude2 * (sin(frequency2 * 2 * pi * t));

square_wave_1 = sinusoid + amplitude2 * square(frequency2*2*pi*t,50);

square_wave_2 = sinusoid + amplitude2 * square(frequency2*2*pi*t,33);

sawtooth = sinusoid + amplitude3 * sawtooth(frequency3*pi*t);


figure;hold on
plot(t,sinusoid)
plot(t,sinusoid2,'k')
plot(t,square_wave_1,'r')
plot(t,square_wave_2,'g')
plot(t,sawtooth,'c')

请注意,我的锯齿代码对于某些频率和振幅看起来很糟糕。关心它。