Function Ouput Array With Repeated Elemnts
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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 Kommentare
Guillaume
am 2 Mai 2018
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
am 2 Mai 2018
Guillaume
am 2 Mai 2018
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
am 2 Mai 2018
Chris Shortgeorge
am 2 Mai 2018
Guillaume
am 2 Mai 2018
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
am 2 Mai 2018
Antworten (0)
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!