Create a 10 Khz square wave in Matlab.

Thread Starter

ynaji

Joined Jan 28, 2007
10
Can you please help ? I am trying to plot a square wave with 10 khz frequency. I am able to plot a square wave with 2 cycle below is the code.

n = 0:255;
t = n/256;
x = [ ones(1,64),-ones(1,64), ones(1,64), -ones(1,64)];
plot(t,x);
 

Thread Starter

ynaji

Joined Jan 28, 2007
10
There is nothing wrong with code. I know how to do 2 cycle square wave and not 10 Khz square wave. The code can do 2 cycle square wave . but the assignement required 10 khz.

Please help if ;you ca.
 

Papabravo

Joined Feb 24, 2006
21,225
So what properties would a 10 kHz square wave have in matlab that your two cycle squarewave does not have? If you say on your plot that the horizontal axis represnets 200 microseconds and that each division in your array represents (200/256) microseconds then you are home free. What is the major malfunction here? I don't get it.
 

Dave

Joined Nov 17, 2003
6,969
The problem with generating the square wave in Matlab in the way above is that the result is retained within a matrix. Therefore for an arbitrarily long signal, you need an arbitrary sized matrix.

You need to specify what the signal length would be and code accordingly. What is the required signal length?

Dave
 
Top