简体   繁体   English

如何在Matlab中产生具有波动的正弦信号?

[英]How a generate a sinusoidal signal having a ripple in matlab?

I need a sinusoidal wave with a frequency of 50 Hz and an amplitude of 50. Further, I need aa triangle ripple of (+10 to -10) and a frequency of 1000 Hz along the sinusoidal wave, as shown below 我需要一个频率为50 Hz,振幅为50的正弦波。此外,我还需要一个正弦波的(+10到-10)三角形波纹和一个频率为1000 Hz的正弦波,如下所示

示例图片

the average value is sinusoid wave but the not the actual wave form is with ripple(ie pulsating in form a triangle). 平均值是正弦波,但不是实际的波形是带有波纹(即以三角形形式脉动)。 the original wave form is a triangular propagating(moving) in form a sinusoidal wave 原始波形是正弦波形式的三角传播(移动)

` `

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;`

I don't know how to proceed next. 我不知道下一步如何进行。

I am going to do the question without using your code, I hope you are not offended, but it is difficult to understand all your variables and also some of your vars are missing and I cannot run your code: 我将不使用您的代码就做这个问题,希望您不会受到冒犯,但是很难理解您所有的变量,并且您的某些变量丢失了,我无法运行您的代码:

First let's create a range: 首先让我们创建一个范围:

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)

那里有

I think that in your case you want to experiment with sawtooth 's frequency and amplitude. 我认为在您的情况下,您想尝试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')

Pay attention, my code for the sawtooth looks bad for some frequencies and amplitudes.. Care with that. 请注意,我的锯齿代码在某些频率和振幅下看起来很糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM