Obtaining Sine Wave From Square Wave

5 views (last 30 days)
I have a square wave but this wave is not an ideal square wave. What I mean is, for example from the first sample of positive peak to the last sample of the positive peak, I have 100 datas. In the next positive peak, I have 91 datas. I want to plot a sine wave which changes adaptively by the number of samples in the positive and negative peaks. This sine wave's positive period should end when the square waves positive peak drops to the zero. Or the best continuous wave that fits with this square wave. Thanks for your advices.
Image Analyst
Image Analyst on 28 Sep 2022
"I have a square wave" <== but you forgot to attach it. Please attach it as a .mat or .txt file with the paperclip icon.

Sign in to comment.

Accepted Answer

Chunru on 28 Sep 2022
% generate a square wave with no fixed period
f = 0.125; fs=1;
s = 0.3+sin(2*pi*f*(0:40)); % a sine wave with offset
x =2* (s>0) -1; % square wave
y = lowpass(x, f*1.5, fs);
hold on
tinkyminky93 on 29 Sep 2022
Simply low pass filtering my square wave gives me a sine wave. Seems like I do not need a solution like that.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by