简体   繁体   中英

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

示例图片

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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