Why am I receiving this error "Unrecognized function or variable '"plotspec" Error in lab2q2 (line 20) plotspec(xx,fs,256); grid on ?
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Star Strider
2022-9-7
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 个)
vamshi sai yele
2022-9-14
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!