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!