I can't seem to get matlab scalogram program to run without the following errors...
조회 수: 4 (최근 30일)
이전 댓글 표시
Below Ilisted the original scalogram matlab program…then I listed the beginning of the program which I ran but receive a bunch of errors.please help
Fs = 11718.75; t = timeold(nsp:nep); %Frq = 10; x = data(nsp:nep); plot(x,'r'); axis tight title('Signal'); xlabel('Time or Space') %Compute the power spectral density (PSD) estimate using spectral estimation of the signal. Then, we find the main frequency by looking at the spectral density and locating the frequency at which the PSD reaches its maximum. h = spectrum.welch; Hpsd = psd(h,x,'Fs',Fs); hLIN = plot(Hpsd); xdata = get(hLIN,'XData'); ydata = get(hLIN,'ydata'); [dummy,idxMax] = max(ydata); FreqMax = xdata(idxMax) hold on ylim = get(gca,'YLim'); plot([FreqMax,FreqMax],ylim,'m--') %FreqMax = %7.8125 %This result is an approximate value of the "true frequency." %Now, we compute the continuous wavelet transform using the gaus4 wavelet and we will see where to find spectral information. wname = 'gaus4'; scales = 1:1:128; coefs = cwt(x,scales,wname); %Using the function scal2freq, we can compute the correspondence table of scales and frequencies. This table depends on the selected wavelet. We search the scale that corresponds to the frequency Frq used to design the signal. TAB_Sca2Frq = scal2frq(scales,wname,1/Fs); clf; plot(TAB_Sca2Frq); axis tight; grid hold on plot([scales(1),scales(end)],[Frq Frq],'m--') set(gca,'YLim',[0 100]) title('Correspondence Table of Scales and Frequencies'); xlabel('Scale') ylabel('Frequency') %We find the scale Sca corresponding to the frequency Frq for the wavelet gaus4. [~,idxSca] = min(abs(TAB_Sca2Frq-Frq)); Sca = scales(idxSca) Sca = 50 %Now, we use continuous wavelet analysis to compute the scalogram of wavelet coefficients using the wavelet gaus4. Plot this scalogram and an horizontal line corresponding to the scale Sca associated with the frequency Frq. We can see that this line connects the maxima of energy in the scalogram. wscalogram('image',coefs,'scales',scales,'ydata',x); hold on plot([1 size(coefs,2)],[Sca Sca],'Color','m','LineWidth',2); %In the scalogram, maxima of energy are detected at scale 50, which corresponds to frequency 10. This is one method of using wavelet analysis to obtain spectral information. %We can also use a contour plot to view the spectral information. clf; coefs = cwt(x,scales,wname,'scalCNT'); hold on plot([1 size(coefs,2)],[Sca Sca],'Color','m','LineWidth',2); %The location of frequency information in the scalogram depends on the wavelet used for the analysis. Some wavelets are able to detect the frequency location very well. Now, we will show how other wavelets perform. %Note that the value of the scale Sca corresponding to the frequency Frq also depends on the wavelet. Good detection with Mexican hat wavelet wname = 'mexh'; TAB_Sca2Frq = scal2frq(scales,wname,1/Fs); [~,idxSca] = min(abs(TAB_Sca2Frq-Frq)); Sca = scales(idxSca) %Sca = %25 clf; coefs = cwt(x,scales,wname,'scalCNT'); hold on plot([1 size(coefs,2)],[Sca Sca],'Color','m','LineWidth',2); %Good detection with Morlet wavelet wname = 'morl'; TAB_Sca2Frq = scal2frq(scales,wname,1/Fs); [~,idxSca] = min(abs(TAB_Sca2Frq-Frq)); Sca = scales(idxSca) %Sca = %clf; coefs = cwt(x,scales,wname,'scalCNT'); hold on plot([1 size(coefs,2)],[Sca Sca],'Color','m','LineWidth',2);
wname = 'haar'; TAB_Sca2Frq = scal2frq(scales,wname,1/Fs); [~,idxSca] = min(abs(TAB_Sca2Frq-Frq)); Sca = scales(idxSca) Sca = 100 clf; coefs = cwt(x,scales,wname,'scalCNT'); hold on plot([1 size(coefs,2)],[Sca Sca],'Color','m','LineWidth',2);
====================================================================
h = spectrum.welch; Hpsd = psd(h,x,'Fs',Fs); hLIN = plot(Hpsd); *Error using welchparse>segment_info (line 180) The length of the segments cannot be greater than the length of the input signal.
Error in welchparse (line 34) [L,noverlap,win] = segment_info(M,win,noverlap);
Error in welch (line 40) [x,M,isreal_x,y,Ly,win,winName,winParam,noverlap,k,L,options] = ...
Error in pwelch (line 121) [varargout{1:nargout}] = welch(x,esttype,varargin{:});
Error in spectrum.welch/thispsd (line 19) [Pxx W] = pwelch(x,...
Error in spectrum.abstractspectrum/psd (line 16) [Pxx W] = thispsd(this,x,opts); % Produces spectrum with pos freq only! *
답변 (3개)
Wayne King
2013년 12월 7일
I agree with cyclist -- you should definitely always format your code.
There error you post has nothing to do with the wavelet scalogram. The error above is coming from the Welch PSD estimator.
The error seems to indicate that the length of your input, x, is less than 64 samples in length which is the default segment length you get with spectrum.welch.
So the following example will produce the same error:
x = randn(60,1);
h = spectrum.welch;
psd(h,x)
If your data is really less than 64 samples in length, I don't think a Welch PSD estimate is going to be very useful. You should probably just use spectrum.periodogram.
RUSTU MURAT DEMIRER
2024년 4월 9일
Error in cwt>plotscalogramfreq (line 869)
alpha(A1,0.4);
Error in cwt (line 338)
plotscalogramfreq(FourierFactor,sigmaT,cfs,freq,t,tfnormfreq);
cwt command does not work in MATLAB 2023b. I spent a lot of time to install and then installed toolboxes. Now I do not want re-install gain.
When you call the cwt function, simply assign its output to variables. This approach computes the CWT but doesn't plot the scalogram by default.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Continuous Wavelet Transforms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!