How do I plot a phase plot for FFT and code time history for down-sampled signal?

3 Ansichten (letzte 30 Tage)
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]
data = 12×2
0 0.8297 0.0083 0.8298 0.0167 0.8288 0.0250 0.8290 0.0333 0.8284 0.0417 0.8271 0.0500 0.8268 0.0583 0.8268 0.0667 0.8269 0.0750 0.8271
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)
Index exceeds the number of array elements. Index must not exceed 12.
grid
xlabel('frequency')
ylabel('Amplitude')

Akzeptierte Antwort

Star Strider
Star Strider am 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]
data = 12×2
0 0.8297 0.0083 0.8298 0.0167 0.8288 0.0250 0.8290 0.0333 0.8284 0.0417 0.8271 0.0500 0.8268 0.0583 0.8268 0.0667 0.8269 0.0750 0.8271
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 Kommentare
omar ali
omar ali am 8 Mai 2023
Thanks for assisting with your obvious expertise!
This is my first time using matlab and for filtering I came across a simple code for our case above but it displayed error message
inputSignal = (t, s);
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters
F = 8
Fs = 30
[y, x] = butter(5, F/(Fs/2), 'low’)
inputSignal = (t, s);
outSignal = filter(y, x, inputSignal);
plot(outSignal)
Star Strider
Star Strider am 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.
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by