What should I revise on my short code so that matlab can depict the given complex spectrum?

Hello!
It's the second time I use matlab in order to solve a problem. I want to depict the complex spectrum of a signal. I write beneath my code. It seems to be correct because matlab does not throw any failure, the value of the parameters appear in the workspace area but the graph of the functions with the appropriate name of labels and grid are not visible. Please help me how to revise my code so as to see the graph of the functions with the labels on one diagram. My code:
>> omega=0:0001:1; >> spectrum=20./(j.*omega)-20./(j.*omega).*exp(-j.*omega.*200)-1./(5*((j.*omega).^2))-1./(5*((j.*omega).^2)).*exp(-j.*omega.*100); >> spectrumabs=abs(spectrum); >> spectrummax=max(spectrumabs); >> eps=0.05.*spectrummax; >> plot(omega, spectrumabs, [0 1], [eps eps]); // After this commmand only a line appears >> grid //After this command only a gridded coordinate system appears and the line disappeared >> title('Spectrum of Amplitude'); //After this command only the title is visible beyond the coordinate system without grid >> xlabel('w[Mrad/s]') // After this command only the w[Mrad/s] label is visible >> ylabel('|H(jw)|') // After this command only the H(jw) label is visible

Answers (1)

Leslie - look closely at how you are defining omega
omega=0:0001:1
The step size is 0001 or just 1, and so omega is a vector of two elements: 0 and 1. This should probably be more like
omega=0:0.0001:1;
Note also that you have declared a local variable called eps. MATLAB already has a built-in method named eps which returns the distance from 1.0 to the next largest double-precision number, that is eps = 2^(-52). Consider renaming this variable to something else to avoid conflicts with the function (that could prove troublesome when debugging errors). _

2 Comments

Thank you for your fast answer. Unfortunately it did not solve my problem.
Try stepping through the code and look at the variables. What is omega and what does * spectrumabs* become? Does it make sense given your equation? Running the above code, with the change to omega, does display the omega vs. spectrumabs plot (in blue) with the second plot in green. Does your figure not show either or both of these?

Sign in to comment.

Asked:

on 6 Oct 2014

Commented:

on 6 Oct 2014

Community Treasure Hunt

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

Start Hunting!