Calculate and Plot Fourier function

1 次查看(过去 30 天)
Hi there,
I have made some calculation on paper and would like to visualise the result by plotting it in MATLAB. However I can't seem to get result that I expect. I have attached a screenshot of the function and the code that I have until now. I would very much appreciate some help on with this.
%
clear;
clc;
%
Fs = 10000000; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.01; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%
n = 1:50;
%
Fm = 1e3; %Signal frequency for omega(m).
Fc = 100e3; %Signal frequency for omega(c).
Am = 1/10;
Ac = 5/10;
%
A1 = Am*Ac/2*(sin(2*pi*Fc*t));
A2 = Am*Ac/pi;
A3 = A1-A2;
A4 = cos(n*2*pi*Fm*t-2*pi*Fc*t);
A5 = cos(n*2*pi*Fm*t+2*pi*Fc*t);
%
A6 = A3-1/n*((A4-A5));
%

回答(1 个)

nanren888
nanren888 2017-4-1
编辑:nanren888 2017-4-1
>> tmp01 Error using * Inner matrix dimensions must agree.
Error in tmp01 (line 17) A4 = cos(n*2*pi*Fm*t-2*pi*Fc*t);
>>
Is this what you mean?
Posting the error will help people see where you are & give you an answer that is useful to you. . The error appears because n is a row vector ([50,1]) & t is a column ([100000,1]) You tell Matlab to do the multiply n*...*t & the inner dimensions don't match. (Which they shouldn't)
Did you intend to an outer product? to create a resulting matrix ([50,100000])? or perhaps its transpose?
If so, transposing each of them might help, or swapping the order of the multiplications?

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by