Develop a cleaner stem plot (Magnitude Spectra)
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Terry Carney
il 10 Mag 2021
Risposto: Star Strider
il 10 Mag 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/613035/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/613040/image.png)
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 Commenti
Risposta accettata
Star Strider
il 10 Mag 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Biomedical Signal Processing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!