resample gives dimension error

조회 수: 4 (최근 30일)
Thomas Carroll
Thomas Carroll 2013년 12월 4일
답변: Jenny 2015년 2월 26일
When I use the resample function, I get a dimension error. Here is the example used in the MATLAB help file, with the output:
fs1 = 10; % Original sampling frequency in Hz
t1 = 0:1/fs1:1; % Time vector
x = t1; % Define a linear sequence
y = resample(x,3,2); % Now resample it
Error using + Matrix dimensions must agree.
Error in firls (line 161) b = b + (F(s+1)*(m*F(s+1)+b1)*sinc(2*k*F(s+1)) ...
Error in resample (line 85) h = p*firls( L-1, [0 2*fc 2*fc 1], [1 1 0 0]).*kaiser(L,bta)' ;

채택된 답변

Wayne King
Wayne King 2013년 12월 4일
I'm not sure if you have a non-MathWorks' (modified) version of firls(), but the code you entered above should work:
fs1 = 10;
t1 = 0:1/fs1:1; % Time vector
x = t1; % Define a linear sequence
y = resample(x,3,2); % Now resample it
Can you clear you workspace and copy and paste the above?
If you enter
>>which firls
Do you get something back like:
matlab\toolbox\signal\signal\firls.m
Also, which version of MATLAB are you using?

추가 답변 (6개)

Thomas Carroll
Thomas Carroll 2013년 12월 4일
Wayne, I cleared the workspace and entered your code, but I got the same result. When I entered >>which firls
I got
/Applications/MATLAB_R2013b.app/toolbox/signal/signal/firls.m
I am using version 2013b
  댓글 수: 1
Wayne King
Wayne King 2013년 12월 4일
Thomas, I have to look around for a Mac to try this on, but it works on Windows and Linux R2013b. This is very strange- I'd be very surprised that this behavior would differ on Mac
I'm assuming if you use which for resample.m you also get a path like above?

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


Thomas Carroll
Thomas Carroll 2013년 12월 4일
Wayne,
Using which for resample.m gives the same path.
I did have a few system crashes while running some C programs, after which I had to reactivate MATLAB. Could a file have been damaged? I'm using OSX 10.8.5. I only have the signal processing toolbox licensed for 1 machine, so I can't try this somewhere else.

Wayne King
Wayne King 2013년 12월 4일
편집: Wayne King 2013년 12월 4일
Let's look at all the functions called by your code. Execute the following:
profile on -history
fs1 = 10;
t1 = 0:1/fs1:1; % Time vector
x = t1; % Define a linear sequence
y = resample(x,3,2); % Now resample it
p = profile('info');
for n = 1:size(p.FunctionHistory,2)
if p.FunctionHistory(1,n)==0
str = 'entering function: ';
else
str = ' exiting function: ';
end
disp([str p.FunctionTable(p.FunctionHistory(2,n)).FunctionName]);
end
Now you should get a list like this:
entering function: resample
entering function: rat
exiting function: rat
entering function: firls
entering function: signal\private\firchk
exiting function: signal\private\firchk
entering function: sinc
exiting function: sinc
entering function: sinc
exiting function: sinc
entering function: sinc
exiting function: sinc
entering function: sinc
exiting function: sinc
exiting function: firls
entering function: kaiser
entering function: signal\private\check_order
exiting function: signal\private\check_order
exiting function: kaiser
entering function: upfirdn
entering function: upfirdn>validateinput
entering function: intmax
exiting function: intmax
exiting function: upfirdn>validateinput
entering function: signal\private\upfirdnmex
exiting function: signal\private\upfirdnmex
exiting function: upfirdn
exiting function: resample
Is it possible that you have a local copy of one of those functions? like upfirdn, etc. ?
  댓글 수: 1
Wayne King
Wayne King 2013년 12월 4일
The code should work on Mac -- just confirmed.

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


Thomas Carroll
Thomas Carroll 2013년 12월 4일
It looks like things start the same, but there are fewer calls to sinc before firls exits. I'm guessing the rest of the calls are error handlers?
Should I try to reinstall the latest MATLAB?
entering function: resample
entering function: rat
exiting function: rat
entering function: firls
entering function: signal/private/firchk
exiting function: signal/private/firchk
entering function: sinc
exiting function: sinc
entering function: sinc
exiting function: sinc
exiting function: firls
exiting function: resample
entering function: workspacefunc
entering function: workspacefunc>getCleanupHandler
entering function: workspacefunc>create@(~,~)com.mathworks.mlwidgets.workspace.MatlabWorkspaceListener.swl(swl)
exiting function: workspacefunc>create@(~,~)com.mathworks.mlwidgets.workspace.MatlabWorkspaceListener.swl(swl)
entering function: onCleanup>onCleanup.onCleanup
exiting function: onCleanup>onCleanup.onCleanup
exiting function: workspacefunc>getCleanupHandler
entering function: workspacefunc>getWhosInformation
entering function: com.mathworks.mlwidgets.workspace.WhosInformation
exiting function: com.mathworks.mlwidgets.workspace.WhosInformation
exiting function: workspacefunc>getWhosInformation
entering function: onCleanup>onCleanup.delete
entering function: workspacefunc>@(~,~)com.mathworks.mlwidgets.workspace.MatlabWorkspaceListener.swl(swl)
exiting function: workspacefunc>@(~,~)com.mathworks.mlwidgets.workspace.MatlabWorkspaceListener.swl(swl)
exiting function: onCleanup>onCleanup.delete
exiting function: workspacefunc
entering function: workspacefunc
entering function: workspacefunc>getShortValueObjectsJ
entering function: workspacefunc>getShortValueObjectJ
entering function: workspacefunc>num2complex
entering function: workspacefunc>createComplexScalar
entering function: codetools/private/dataviewerhelper
entering function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper
exiting function: workspacefunc>createComplexScalar
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getShortValueObjectJ
entering function: workspacefunc>getShortValueObjectJ
entering function: workspacefunc>num2complex
entering function: workspacefunc>getAbstractValueSummaryJ
entering function: workspacefunc>getclass
exiting function: workspacefunc>getclass
exiting function: workspacefunc>getAbstractValueSummaryJ
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getShortValueObjectJ
entering function: workspacefunc>getShortValueObjectJ
entering function: workspacefunc>num2complex
entering function: workspacefunc>getAbstractValueSummaryJ
entering function: workspacefunc>getclass
exiting function: workspacefunc>getclass
exiting function: workspacefunc>getAbstractValueSummaryJ
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getShortValueObjectJ
exiting function: workspacefunc>getShortValueObjectsJ
exiting function: workspacefunc
entering function: workspacefunc
entering function: workspacefunc>getStatObjectsJ
entering function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectM
entering function: workspacefunc>lookupStatFunction
exiting function: workspacefunc>lookupStatFunction
entering function: workspacefunc>local_min
exiting function: workspacefunc>local_min
exiting function: workspacefunc>getStatObjectM
entering function: workspacefunc>num2complex
entering function: workspacefunc>createComplexScalar
entering function: codetools/private/dataviewerhelper
entering function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper
exiting function: workspacefunc>createComplexScalar
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectM
entering function: workspacefunc>lookupStatFunction
exiting function: workspacefunc>lookupStatFunction
entering function: workspacefunc>local_min
exiting function: workspacefunc>local_min
exiting function: workspacefunc>getStatObjectM
entering function: workspacefunc>num2complex
entering function: workspacefunc>createComplexScalar
entering function: codetools/private/dataviewerhelper
entering function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper
exiting function: workspacefunc>createComplexScalar
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectM
entering function: workspacefunc>lookupStatFunction
exiting function: workspacefunc>lookupStatFunction
entering function: workspacefunc>local_min
exiting function: workspacefunc>local_min
exiting function: workspacefunc>getStatObjectM
entering function: workspacefunc>num2complex
entering function: workspacefunc>createComplexScalar
entering function: codetools/private/dataviewerhelper
entering function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper
exiting function: workspacefunc>createComplexScalar
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getStatObjectJ
exiting function: workspacefunc>getStatObjectsJ
exiting function: workspacefunc
entering function: workspacefunc
entering function: workspacefunc>getStatObjectsJ
entering function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectM
entering function: workspacefunc>lookupStatFunction
exiting function: workspacefunc>lookupStatFunction
entering function: workspacefunc>local_max
exiting function: workspacefunc>local_max
exiting function: workspacefunc>getStatObjectM
entering function: workspacefunc>num2complex
entering function: workspacefunc>createComplexScalar
entering function: codetools/private/dataviewerhelper
entering function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper
exiting function: workspacefunc>createComplexScalar
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectM
entering function: workspacefunc>lookupStatFunction
exiting function: workspacefunc>lookupStatFunction
entering function: workspacefunc>local_max
exiting function: workspacefunc>local_max
exiting function: workspacefunc>getStatObjectM
entering function: workspacefunc>num2complex
entering function: workspacefunc>createComplexScalar
entering function: codetools/private/dataviewerhelper
entering function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper
exiting function: workspacefunc>createComplexScalar
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectJ
entering function: workspacefunc>getStatObjectM
entering function: workspacefunc>lookupStatFunction
exiting function: workspacefunc>lookupStatFunction
entering function: workspacefunc>local_max
exiting function: workspacefunc>local_max
exiting function: workspacefunc>getStatObjectM
entering function: workspacefunc>num2complex
entering function: workspacefunc>createComplexScalar
entering function: codetools/private/dataviewerhelper
entering function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper>upconvertIntegralType
exiting function: codetools/private/dataviewerhelper
exiting function: workspacefunc>createComplexScalar
exiting function: workspacefunc>num2complex
exiting function: workspacefunc>getStatObjectJ
exiting function: workspacefunc>getStatObjectsJ
exiting function: workspacefunc
  댓글 수: 1
Wayne King
Wayne King 2013년 12월 4일
I would, yes. There's no reason it should not work

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


Thomas Carroll
Thomas Carroll 2013년 12월 4일
Wayne, I copied the girls.m my MATLAB was using by setting "stop on errors" and saving girls.m to my desktop as firls_test.m. Is it possible to compare with your version of firls.m? I attached the file.
  댓글 수: 4
Thomas Carroll
Thomas Carroll 2013년 12월 5일
As a followup: Reinstalling MATLAB worked, but I had another system crash from accidentally trying to work with some huge files. I had to reactivate MATLAB, but now I get the same problem with firls.m. Could there be some environment variable that gets altered? Reinstalling MATLAB every time this happens takes a lot of extra time.
Wayne King
Wayne King 2013년 12월 5일
I agree this is not optimal. Thomas, can you contact tech support about this question. It sounds to me like there should be some investigating done here. You can refer them to this thread. I think you'll find them very responsive.

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


Jenny
Jenny 2015년 2월 26일
This error could be caused by a third party toolbox or function shadowing the FIRLS function.
If you run the command:
>> which -all firls
it should list only MATLAB functions. If there's another FIRLS function listed, not provided by MathWorks, then uninstall the toolbox or rename your function to something else.

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by