Why am I receiving this error "Unrecognized function or variable '"plotspec" Error in lab2q2 (line 20) plotspec(xx,fs,256); grid on ?

8 views (last 30 days)
amps = [100, 120];
freqs = [800,2000];
phases = [0.6*pi, -0.1*pi];
fs = 8000;
tStart = [0.1, 0.1];
durs = [0.4,0.4];
maxTime = max((sum(tStart) + sum(durs))) + 0.1; %-- Add time to show ...
% signal ending
durLengthEstimate = ceil(maxTime*fs);
tt = (0:durLengthEstimate)*(1/fs); %-- be conservative ...(add one)
xx = 0*tt; %--make a vector of zeros to hold the total ...signal
for kk = 1:length(amps)
nStart = round(fs .* tStart(kk))+1; %-- add one to avoid zero index
xNew = shortSinus(amps(kk), freqs(kk), phases(kk), fs, durs(kk));
Lnew = length(xNew);
nStop = Lnew + nStart - 1; %======== Add code
xx(nStart:nStop) = xx(nStart:nStop) + xNew;
end
plotspec(xx,fs,256); grid on
tt = (1/fs)*(0:length(xx)-1);
plot( tt, xx );
function xs = shortSinus(amp, freq, pha, fs, dur)
% amp = amplitude
% freq = frequency in cycle per second
% pha = phase, time offset for the first peak
% fs = number of sample values per second
% dur = duration in sec
%
tt = 0 : 1/fs : dur; % time indices for all the values
xs = amp * cos( freq*2*pi*tt + pha );
end
  1 Comment
Star Strider
Star Strider on 7 Sep 2022
If the code is provided as a homework laboratory exercise, be certain you have downloaded all the functions relevant to it, and copied them to an appropriate directory on your MATLAB search path. The ‘plotspec’ function is likely one of them, and I assume that ‘shortSinus’ is also one of them.

Sign in to comment.

Answers (1)

vamshi sai yele
vamshi sai yele on 14 Sep 2022
I have checked my resources and as far as my knowledge I could say that 'plotSpec' might not a function in any MATLAB toolbox.
I suggest you to make sure you don't miss any file loading into the root folder/directory before you run the script so that nothing miss from directory and everything has a proper defined function/files.

Community Treasure Hunt

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

Start Hunting!