How do I plot a phase plot for FFT and code time history for down-sampled signal?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
Thus far, i have completed this code which gave me a frequency vs amplitude graph. I'm ussure how to get a phase graph from this or time history of down sampled signal by a given rate etc I nwould be grateful for assistance for this.
data = [0 0.829668000000000
0.00833300000000000 0.829801000000000
0.0166670000000000 0.828810000000000
0.0250000000000000 0.829008000000000
0.0333330000000000 0.828352000000000
0.0416670000000000 0.827073000000000
0.0500000000000000 0.826807000000000
0.0583330000000000 0.826828000000000
0.0666670000000000 0.826857000000000
0.0750000000000000 0.827056000000000
0.0833330000000000 0.827139000000000
0.0916670000000000 0.828689000000000]
t = data(:,1);
s = data(:,2);
Ts= 0.0083;
Fs=1/Ts;
Fn= Fs/2;
L=4000;
smean=mean(s);
Fts=fft(s-smean)/L;
Fv= linspace(0,1,fix(L/2)+1)*Fn;
Iv=1:numel(Fv);
figure
plot(Fv,abs(Fts(Iv))*2)
grid
xlabel('frequency')
ylabel('Amplitude')
0 commentaires
Réponse acceptée
Star Strider
le 7 Mai 2023
Perhaps this —
data = [0 0.829668000000000
0.00833300000000000 0.829801000000000
0.0166670000000000 0.828810000000000
0.0250000000000000 0.829008000000000
0.0333330000000000 0.828352000000000
0.0416670000000000 0.827073000000000
0.0500000000000000 0.826807000000000
0.0583330000000000 0.826828000000000
0.0666670000000000 0.826857000000000
0.0750000000000000 0.827056000000000
0.0833330000000000 0.827139000000000
0.0916670000000000 0.828689000000000]
t = data(:,1);
s = data(:,2);
Ts= 0.0083;
Fs=1/Ts;
Fn= Fs/2;
L=size(data,1);
smean=mean(s);
NFFT = 2^nextpow2(L);
FTs=fft((s-smean).*hann(L))/L;
Fv= linspace(0,1,NFFT/2+1)*Fn;
Iv=1:numel(Fv);
figure
subplot(2,1,1)
plot(Fv,abs(FTs(Iv))*2)
grid
ylabel('Amplitude')
subplot(2,1,2)
plot(Fv,rad2deg(angle(FTs(Iv))))
grid
xlabel('Frequency')
ylabel('Phase (°)')
Also consider using unwrap for the radian phase, as: ‘rad2deg(unwrap(angle(FTs(Iv))))’. (I made a few improvements in my original code.)
.
4 commentaires
Star Strider
le 8 Mai 2023
As always, my pleasure!
I would do this instead —
F = 8
Fs = 30
[y, x] = butter(5, F/(Fs/2), 'low’)
inputSignal = s;
outSignal = filtfilt(y, x, inputSignal);
figure
plot(t, outSignal)
There is no reason to include the time vector in the signal being filtered, so I eliminated it here.
However if you want to concatenate two column vectors, use square brackets as [a, b] (although the comma is optional) and if you want to concatenate two row vectors [a; b] using the semicolon to create a second row (to vertically concatenate them). In all instances, the vectos must have the same row and column dimensions.
Actually, I would design the filter differently (I prefer elliptic filters because they are more computationally efficient), however to design a Butterworth filter I would begin with the buttord function, then butter, however producing zero-pole-gain output, and then use the zp2sos function to produce a second-order-section representation, and call filtfilt as:
outSignal = filtfilt(sos, g, inputSignal);
The filtering will be more effective and the filter will always be stable with these changes.
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Transforms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
