Develop a cleaner stem plot (Magnitude Spectra)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Terry Carney
el 10 de Mayo de 2021
Respondida: Star Strider
el 10 de Mayo de 2021
Hello,
My magnitude spectra of an unfiltered and filter ERP is showing multiple (and possibly unnecessary) plots on the left and right side of their stem plots, like so:
How can I make these plot look "cleaner" attached is a text file with data related to these plots.
ync = [.25 .5 .25]; %yn coefficients
ync1 = [-.085 .342 .485 .342 -.085]; %yn1 coefficients
ync2 = [-21/231 14/231 39/231 54/231 59/231 54/231 39/231 14/231 -21/231] %yn2 coefficients
Fs1 = 500; %Sampling Frequency
Ts1 = 1/Fs1; %Sampling Time
t1 = 0:1/Fs1:1-1/Fs1;
erp = load("data.txt");
erpMean = mean(erp, 2);
%Setting up for stem() [Unfiltered]
N = length(erpMean);
X = fft(erpMean);
X=1/N*abs(X);
X=[X(1) 2*X(2:end)']; %Converting column to row
f=0:Fs1/N:Fs1-Fs1/N;
%Setting up for stem() [Filtered]
z = filter(ync2,1,erpMean);
N1 = length(z);
X1 = fft(z);
X1 = 1/N1*abs(X1);
X1 = [X1(1) 2*X1(2:end)'] %Converting column to row
f1 = 0:Fs1/N1:Fs1-Fs1/N1;
figure(13)
plot(t1,erpMean);
title("Unfiltered ERP");
ylabel("Amplitude (mV)")
xlabel("Time(s)");
figure(14)
plot(t1,z);
title("Filtered ERP with Least-Square Polynomial Impulse")
ylabel("Amplitude (mV)");
xlabel("Time(s)");
%Magnitude Spectra
figure(15)
stem(f,X,'LineWidth',2);
grid on;
title("Unfiltered");
xlabel("Frequency (Hz)")
figure(16)
stem(f1,X1,'LineWidth',2);
grid on
title("Filtered")
xlabel("Frequency (Hz)")
0 comentarios
Respuesta aceptada
Star Strider
el 10 de Mayo de 2021
These are two-sided fft plots.
I’m not certain what ‘cleaner’ is in this context, however using the fftshift function, then creating the correct frequency vector as:
f2 = linspace(-Fs1/2, Fs1/2, N);
and:
Xs = fftshift(X);
X1s = fftshift(X1);
stem(f2, Xs, '.')
stem(f2, X1s, '.')
could improve the appearance of the plots.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Multirate Signal Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!