# Matlab Help, generating square wave, and sinusoid

Discussion in 'Programmer's Corner' started by dcwang3, Jan 28, 2010.

1. ### dcwang3 Thread Starter New Member

Nov 27, 2009
7
0
Hi:

I'm working on a matlab project, and I do not have too much knowledge in Matlab. Here is my problem:

-------
1) The sampling rate assumed in hw2channel is 10Mhz. This means that the time elapsed between two adjacent samples in any signal vector is 100ns. You have to keep this in mind when generating signals in MATLAB to test the channgel.

Generate an impulse, a square wave of fundamental frequency 1MHz, and a pure sinusoid of frequency 2.5MHz.

Hint1: In MATLAB, an impulse can represented by an 1 followed by many 0s.
Hint2: For the square wave and sinusoid, since we cannot have infinite length signal vectors in MATLAB, we have to truncate the signals to finite length. As a result when putting these finite-length signals through the channel, transient s will occurs at the beginning and the end. Here we will care mostly about the stead state responses. Hence you will need to generate long enough signal vectors to allow the transients to die down before observing the steady state responses.

----
Here is my code. I do not know if I am initializing it correct, and I am not sure what my t has to be.

Code ( (Unknown Language)):
1.
2. fsample = 10e6;          %sample rate (Hz)
3. square_fs = 1e6;         %frequency of square wave is 1MHz
4. sinusoid_fs = 2.5e6;     %frequency of sinusoid is 2.5MHz
5.
6.
7. gen_impulse = [1,zeros(1,size(t))];       %generate impulse wave
8.
9. gen_square = square(2*pi*square_fs*t);   %generate square wave
10.
11. gen_sin = sin(2*pi*2.5e6*t)
12.

Can someone help?

Thanks