Variable frequency triangular wave

7 次查看(过去 30 天)
HARISH
HARISH 2022-10-25
回答: Yash 2023-9-22
How to make triangular wave with variable frequency that varies over modulators period to obtain more samples in the area with the greatest slope. Carrier wave(triangular wave) should follow this law: ωi = ωc−kf · (sin(ωmt))2 - ωi =ωc, if sin(ωmt)=0 ωi =ωc−kf , if sin(ωmt)=±1.....wm=modulator freq. Wi=triangular wave Freq. K=modulation constant
  6 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2022-10-25
编辑:KALYAN ACHARJYA 2022-10-25
Please share the code (use attachments icon), also share the expected outcomes/results.
HARISH
HARISH 2022-10-25
fm=50; wm=2*pi*fm; t=linspace(0,0.02,500) if sin(wm*t)==0 wi=25*wm; elseif sin(wm*t)==1 wi=5*wm; elseif sin(wm*t)==-1 wi=5*wm; else wi=wm;
end

请先登录,再进行评论。

回答(1 个)

Yash
Yash 2023-9-22
Hi Harish,
I understand that you are interested in generating a triangular wave with variable frequency.
The reason you are obtaining only one value for "wi" is because currently, "wi" is derived from a single value of "wm" based on the value of "sin(wmt)". However, since "t" is an array, "sin(wmt)" will also be an array. Consequently, comparing it to a single value will always yield false, resulting in "wi" being the same as "wm".
To address this, you can iterate over each value of "t" using a loop and calculate the frequency at each time step. By doing so, you will be able to obtain the desired variable frequency for the triangular wave.
It is important to note that the y-axis data for a triangular wave is always fixed, alternating between 0 and 1. Therefore, you only need to calculate the corresponding time values at which these transitions occur.
You can calculate the time values by utilizing the frequency at each time stamp as shown in the example below:
% Initialize variables here
% Array for storing timestamp values of 0 and 1
ts = zeros(1,length(t));
j=2;
for ti=t(1:end-1)
% Implement your logic to calculate "wi" here
% Once you have the value of "wi" calculate the next time stamp.
ts(j) = ts(j-1) + 2*pi/wi;
j=j+1;
end
% Creating an array of alternating 0 and 1.
yy = 1:length(ts);
yy = mod(yy,2);
plot(ts,yy)
I hope this explanation helps you in implementing the variable frequency triangular wave.
Best Regards
Yash

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by