Function Ouput Array With Repeated Elemnts
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hello everyone, i have the following function :
function [ph]=Inst_Phase_Extraction( Filt_Signal )
ph=zeros(size(Filt_Signal,1),size(Filt_Signal,2));
for i = 1:size(Filt_Signal,1)
%Hilbert Transform
hil=zeros(1,size(Filt_Signal,2));
hil(1,:)=hilbert(Filt_Signal(i,:));
ph(i,:)=atan2(imag(hil(1,:)), real(hil(1,:)));
end
end
The ouput i get (ph) has the 1st row repeated size(Filt_Signal,1) times...
댓글 수: 7
Guillaume
2018년 5월 2일
There's a lot of unnecessary indexing in your code.
function [ph]=Inst_Phase_Extraction( Filt_Signal )
ph = zeros(size(Filt_Signal)); %I'am assuming Filt_Signal is 2d
for row = 1:size(Filt_Signal, 1)
hil = hilbert(Filt_Signal(row, :)); %no need to preallocate hil
ph(row, :) = atan2(imag(hil), real(hil)); %hil(1, :) is the same as hil
end
end
If that code produces the same values for all rows, then that's because the hilbert transform or atan2 produces the same result for the rows of your input. Considering that the documentation of hilbert states that The imaginary part is a version of the original real sequence with a 90° phase shift, I wouldn't be surprised that atan2 produces the same result for all inputs. But I don't know anything about hilbert transforms.
Chris Shortgeorge
2018년 5월 2일
Guillaume
2018년 5월 2일
Right, then show us the inputs and the exact way you call the function with these inputs, so we can see what the problem is ourselves.
Chris Shortgeorge
2018년 5월 2일
Chris Shortgeorge
2018년 5월 2일
Guillaume
2018년 5월 2일
Please, remove all these extra blank lines you've added, then select all the code and press the {}Code button with the code selected.
This will make your posts a lot more readable.
Chris Shortgeorge
2018년 5월 2일
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!