Problem with sin/cos of complex signal



First, a disclaimer:

1: Yes, I'm a student
2: Yes, this is homework
3: Yes, I've been struggling with this for a long time, and could use an extra pair of eyes
3.5: Yes, I'm sure the mistake is something stupid I've done, feel free to tell me so.

The assignment is not hard. Take a complex signal, graph the real and imaginary portions, and then calculate a few sin's and cosine's to show that the real signal is actually the cosine and the imaginary is really the sin

Here's my code (at the end of the post). You'll see if you run it that the signal appears to graph ok in both real and imaginary, but the sin and cosine don't appear to have anything to do with the signal itself.

Did I do something stupid?

Thanks.

%-------------------------START CODE------------------------------------
function [ ] = Lab1_sec3_1_source_code( )
%LAB1_SEC3.1_SOURCE_CODE quick script to run part of lab 1
% No arguments, no output data. just run and watch the graph show up
% By Brian Lojeck, 2/7/09, EE386, Lab 1, Section 3.1

%first, a bit of error checking
if (nargout>0)||(nargin>0)
display('No arguments in or out!'); help Lab1_sec3.1_source_code
return;
end

%next, we set up some basic variables
Amplitude=3;
Phase=-.4*pi;
signalFrequency=10; %signal frequency in hz
sampleFrequency=1000; %how often to sample signal?
errorChkFreq=200; %how often to check results with sin/cos calculations?
numberOfPeriods=3; %how long test run for?



%Now, we use the values above to calculate some more values
signalPeriod=1/signalFrequency; %find duration of signal in seconds
samplePeriod=1/sampleFrequency; %find Ts
totalTimeOfTest=numberOfPeriods*signalPeriod; %find total duration in sec
SampleTimes=0:samplePeriod:totalTimeOfTest; %find time indexes
%of samples
errorChkPeriod=1/errorChkFreq;
errorChkSampleTimes=0:errorChkPeriod:totalTimeOfTest;

%now, we build the data
Samples=Amplitude*exp(j*(2*pi*signalFrequency*SampleTimes+Phase));

%for error checking, we generate sin and cosine data as well
errorChkSamples=Amplitude*exp(j*(2*pi*signalFrequency*errorChkSampleTimes+Phase));
SinData=sin(errorChkSamples);
CosData=cos(errorChkSamples);

%now, we graph
subplot(2,1,1);
plot (SampleTimes,imag(Samples),'r');
hold on;
plot (errorChkSampleTimes,SinData,'k');
legend(['Imaginary Sample Data';'Sin of Sample Data ']);
title('Imaginary Sample Data, Lab 1 Section 3.1');
xlabel('Time (Seconds)');
ylabel('Amplitude');

subplot(2,1,2);
plot (SampleTimes,real(Samples),'r');
hold on;
plot (errorChkSampleTimes,CosData,'k');
legend(['Real Sample Data ';'Cos of Sample Data']);
title('Real Sample Data, Lab 1 Section 3.1');
xlabel('Time (Seconds)');
ylabel('Amplitude');
%-------------------------------------END CODE---------------------------------------
.



Relevant Pages

  • Re: Problem with sin/cos of complex signal
    ... You'll see if you run it that the signal appears to graph ok in both real and imaginary, but the sin and cosine don't appear to have anything to do with the signal itself. ... plot; ... title('Imaginary Sample Data, Lab 1 Section 3.1'); ...
    (comp.soft-sys.matlab)
  • Re: [opensuse] Lies, damned lies and statistics
    ... Recently we have done a poll around the office. ... line with bash/sed/awk and then produce graphs from that, then spline, graph ... GNU 'plot' is then called to display a graph on the screen: ...
    (SuSE)
  • Help needed in ploting graphs in GUI
    ... I am trying to make a graph in the GUI which plots itself ... when the user pushes a pushbutton. ... plot the current data as well as the previous data. ...
    (comp.soft-sys.matlab)
  • Re: Updating a Graph in word
    ... This object was created in MS graph. ... get the info from the form but am finding it difficult to plot the ... The graphing engine is the same one Excel uses. ... This reply is posted in the Newsgroup; ...
    (microsoft.public.word.vba.general)
  • Re: scale_z (set view) problem
    ... clipping is in a rather ... area on this page, called a "plot". ... gnuplot automatically calculates margins between the boundaries of ... This 2D graph rectangle is ...
    (comp.graphics.apps.gnuplot)