Problem with sin/cos of complex signal
- From: "brian" <brian@xxxxxxxxxx>
- Date: Wed, 11 Feb 2009 05:55:05 +0000 (UTC)
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---------------------------------------
.
- Follow-Ups:
- Re: Problem with sin/cos of complex signal
- From: Peter Boettcher
- Re: Problem with sin/cos of complex signal
- From: Rune Allnor
- Re: Problem with sin/cos of complex signal
- From: NZTideMan
- Re: Problem with sin/cos of complex signal
- Prev by Date: fmincon
- Next by Date: exporting fig files to PowerPoint presentation
- Previous by thread: Polyspace orange warning for uint
- Next by thread: Re: Problem with sin/cos of complex signal
- Index(es):
Relevant Pages
|