Failing to plot a fourier transform
Show older comments
Hello,
I've been trying to understand the functioning of modulation and demodulation using a cosine wave, and study how it works in time and frequency domains. Thus, I've put into matlab what the book does, to see it visually.
syms x;
>> y1 = power(sinc(x),2);
>> y2 = cos(2*pi*x);
>> z1 = times(y1,y2)
>> f1 = fourier(y1);
>> f2 = fourier(y2);
>> f3 = fourier(y3);
However, when using fplot to plot the first three (so, the sinc^2, the cosine wave and then the modulated signal z1 = sinc^2(x) * cos(2πt)) everything goes smoothly. Wanting to see whether or not this time-domain function does indeed equal the frequency-domain plots the book shows, I transformed every signal. In theory, f1 should be a Tri, f2 should be two dirac impulses, and f3 should be the convolution of f1 and f2. Here's the issue: when using fplot to plot the frequency-domain functions, I get the following error:
Error using fplot>singleFplot
Input must be a function or functions of a single variable.
Error in fplot>@(f1,f2)singleFplot(cax,{f1,f2},limits,extraOpts,args) (line 208)
hObj = cellfun(@(f1,f2) singleFplot(cax,{f1,f2},limits,extraOpts,args),fn{1},fn{2},'UniformOutput',false);
Error in fplot>vectorizeFplot (line 208)
hObj = cellfun(@(f1,f2) singleFplot(cax,{f1,f2},limits,extraOpts,args),fn{1},fn{2},'UniformOutput',false);
Error in fplot (line 166)
hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);
So, I tried to integrate over x (which, in this example, is time):
>> f1 = fourier(y1,x);
>> f2 = fourier(y2,x);
>> f3 = fourier(z1,x);
Which then led to the following error:
Warning: Error updating ParameterizedFunctionLine.
The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing
remaining symbolic function calls into double array. Argument must be expression that evaluates to number.
Is it possible to plot the frequency-domain functions? If so, what am I doing wrong?
I apologise if the code looks very simple and lackluster but this is my first time using matlab.
Thanks in advance
6 Comments
syms x;
y1 = power(sinc(x),2)
y2 = cos(2*pi*x)
z1 = times(y1,y2)
f1 = fourier(y1)
f2 = fourier(y2)
fplot(z1, [0 2*pi])
%dirac deltas are either 0 or infinite so no useful plot
fplot(f2, [0 100])
fplot(f1, [0 100])
That is caused by the fact that fourier() does not know how to transform cos(x)/x^2 . Wolfram Alpha does know how to transform sinc(x)^2, getting sqrt(pi)/2 times a triangle distribution, or an expression involving five heaviside functions.
Lorenzo Romagnoli
on 5 Nov 2022
Walter Roberson
on 5 Nov 2022
You could switch from symbolic fourier transform to discrete fourier transform fft
Lorenzo Romagnoli
on 6 Nov 2022
Walter Roberson
on 6 Nov 2022
Choose particular x to evaluate the function at; use regular intervals. fft() the function values. This will give you amplitudes at frequencies determined by the spacing in your x values.
Walter Roberson
on 6 Nov 2022
Hmmm, except that fft assumes that the signal is periodic. That can make a significant difference in the plot.
Accepted Answer
More Answers (0)
Categories
Find more on Discrete Fourier and Cosine Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!










