how i can clip sinewave from xaxis
5 views (last 30 days)
Show older comments
Qassem Rajab
on 19 Dec 2020
Commented: Qassem Rajab
on 20 Dec 2020
5 Comments
Les Beckham
on 19 Dec 2020
There are so many things wrong with this apparent homework question that I'm not sure how to even begin to help you. For example:
- Are alpha and beta specified as fractions of a period, fractions of pi, or some other unspecified units?
- What is a "general matlab code"?
- I would not call this a "clipped" sine wave. To me, a "clipped" sine wave is one that has its amplitude limited at some maximum value. This looks like a sine wave that is fed through some type of hysteresis or relay.
Now, moving on to your question in Matlab Answers.
- Where is your attempt at solving this in Matlab code? If you provide it and tell us what isn't working or what you don't know how to fix, the nice people here will be happy to help you fix it.
- Can you write the Matlab code to generate a sine wave?
- Do you know how to use logical indexing to test when certain conditons are true and change the values of an array based on those conditions? For example: signal(index < alpha*dt) = 0.
- If you figure out how to generate the "clipped" signal, do you know how to calculate the THD?
Accepted Answer
Image Analyst
on 19 Dec 2020
Here's a hint to get started. Use repmat(), ones, and zeros() to create a rectangle wave then multiply by the sine wave you create. Starter code (doesn't run until you fix it, which should be easy).
numPoints = 1234; % Whatever - you decide this.
% Create a sine wave.
x = linspace(0, 4*pi, 1000);
period = 4;
amplitude = 3;
y = amplitude * sin(2 * pi * x / period);
subplot(3, 1, 1);
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
% To do: adjust lengths and location of pulses of
% rectangle wave (below) and sine wave (above).
oneCycle = [zeros(1, numPoints), ones(1, numPoints)];
rectangleWave = repmat(oneCycle, [1, 10]);
subplot(3, 1, 2);
plot(rectangleWave, 'b-', 'LineWidth', 2);
grid on;
% Multiply rectangle wave by sine wave.
output = whatever;
subplot(3, 1, 3);
plot(output, 'b-', 'LineWidth', 2);
grid on;
5 Comments
Image Analyst
on 20 Dec 2020
Add 1 to get to the range 0-2, then divide by 2. Or else use rescale
x = rescale(x, 0, 1);
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!