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

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

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.

댓글을 달려면 로그인하십시오.

답변 (1개)

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.

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

질문:

2022년 9월 7일

답변:

2022년 9월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by