how i can clip sinewave from xaxis

5 Comments

how i can do this cliper?
Qassem Rajab
Qassem Rajab on 19 Dec 2020
Edited: Qassem Rajab on 19 Dec 2020
please help me i have only one day to submint the assignment.
Calculate what? Looks like you can create a square wave and multiple it by the sine wave.
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:
  1. Are alpha and beta specified as fractions of a period, fractions of pi, or some other unspecified units?
  2. What is a "general matlab code"?
  3. 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.
  1. 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.
  2. Can you write the Matlab code to generate a sine wave?
  3. 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.
  4. If you figure out how to generate the "clipped" signal, do you know how to calculate the THD?
the qusetion is very clear '_'?

Sign in to comment.

 Accepted Answer

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

its not working
What's not working? Of course my code does not run because I'm sure you're not allowed to turn my program into your professor pretending it is code you wrote all by yourself. I even explictly said that it won't run until you fixed it. But you forgot to tell us your "fixed" code. Please post your latest attempt AFTER you read these links:
clc
clear
f=1;
t=0:1/fs:5;
x=square(2*pi*f*t);
figure(2);plot(t,x,'g','linewidth',2);grid
title('Squre Wave Signal');xlabel('time (in seconds)');
this is code for square wave. the Amplitude is from -1 to 1
how to change it to the 0 and 1 only for squarewave.
help me please.
Add 1 to get to the range 0-2, then divide by 2. Or else use rescale
x = rescale(x, 0, 1);

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!