MATLAB: Plot a signal in the freq domain

bocfftpwelch

Hello!! I am trying to plot this function X= m*((sin(pi*f/2*m)*sin(pi*f/n))/pi*f*cos(pi*f/2*m))^2;
that is in the freq domain, but when I get the plot is empty. This function is the theorically spectrum of a BOC modulation, so I guess that I can not do fft or pwelch or stuff like that, so I dont know how to plot it in the f domain. I thought is gonna be samething easy as
for f=1:100:100000;
X= m*((sin(pi*f/2*m)*sin(pi*f/n))/pi*f*cos(pi*f/2*m))^2;
end
plot(f,X)
but is not working I will appreciate a lot is someone can give me a hint Thanks in advance Nicolas

Best Answer

If the code is setup exactly the way you say above, then there is only one element in "f" and one element in "X". You need to do something like this instead:
% Define m and n
f = 1:100:100000;
X = zeros(size(f)); % Preallocate
for ii=1:numel(f)
X(ii)= m*((sin(pi*f(ii)/2*m)*sin(pi*f(ii)/n))/pi*f(ii)*cos(pi*f(ii)/2*m))^2;
end
Or... skip the for loop
X = m*((sin(pi*f/2*m).*sin(pi*f/n))/pi.*f.*cos(pi*f/2*m)).^2;
Then
plot(f,X)
Related Question