How to remove spurious lines?

Hello everyone! Why do these horizontal lines appear in the last plot and how can I remove them?
fs = 100;
data = load("data.txt");
distance = 0.4;
time = data(:,1);
amplitude = data(:,2);
fstep = 2 : 1 : -1+0.5*fs;
N = numel(fstep)-1;
central_freqs = NaN([1 N]);
filtered = NaN([numel(time) N]);
for i = 1:N
filtered(:,i) = bandpass(amplitude,[fstep(i) fstep(i+1)],fs);
filtered(:,i) = filtered(:,i)/max(abs(filtered(:,i)));
central_freqs(i) = 0.5*(fstep(i) + fstep(i+1));
end
[Freqs,Time] = meshgrid(central_freqs,time);
surf(Freqs,Time,filtered);
shading interp
view([0 90])
ylim([-1 0])
xlim([min(central_freqs) 15])
cb = colorbar;
ylabel(cb,'Amplitude')
xlabel("Frequency (Hz)")
ylabel("time (s)")
title("Initial image")
plot3(Freqs,Time,filtered)
velocity = distance./(Time - 0.25./Freqs);
surf(Freqs,velocity,filtered);
shading interp
ylim([-2 0])
xlim([min(central_freqs) 15])
view([0 90])
cb = colorbar;
ylabel(cb,'Amplitude')
xlabel("Frequency (Hz)")
ylabel("phase velocity (km/s)")
title("Transformed image")
plot3(Freqs,velocity,filtered)
ylim([-2 0])
xlim([2.5 15])

 Respuesta aceptada

Star Strider
Star Strider el 15 de Abr. de 2021

0 votos

Sort ‘velocity’:
[velocity, idx] = sort(velocity);
figure
plot3(Freqs,velocity,filtered(idx))
ylim([-2 0])
xlim([2.5 15])
grid on
producing:
.

8 comentarios

tandemuse
tandemuse el 16 de Abr. de 2021
Thanks this does indeed remove the horizontal lines.
However it also changes the "Transformed image" plot. Should this be the correct one and why?
Star Strider
Star Strider el 16 de Abr. de 2021
My pleasure!
I have no idea what the code actually does, however the sort call only affects that one plot at the end of the code, since nothing is plotted after it.
Change the sort call and the following plot3 call to:
[velocity_sorted, idx] = sort(velocity);
figure
plot3(Freqs,velocity_sorted,filtered(idx))
ylim([-2 0])
xlim([2.5 15])
grid on
to retain the other data as unsorted in any code that follows. The ‘idx’ subscript to ‘filtered’ affects it only in that plot3 call. It retains its original orientation otherwise.
Eliminating the extra lines in the last plot was what was requested, and my code solved that problem.
tandemuse
tandemuse el 16 de Abr. de 2021
Hi Star Strider, I mean that the original code:
surf(Freqs,velocity,filtered);
produces the image "tr1.bmp", while your suggestion:
[velocity_sort, idx] = sort(velocity);
surf(Freqs,velocity_sort,filtered(idx));
produces the image "tr2.bmp". I have attached the two images for you.
The two images show completely different information. Assuming the "tr1.bmp" contained the correct information, I would like to remove from it the vertical yellow lines.
Star Strider
Star Strider el 16 de Abr. de 2021
The information is the same. The difference is that in order to eliminate the spurious straight lines, as was the original request, my code sorts the data, since the spurious straight lines were due to the data not being sorted by ‘velocity’.
My code elliminates the vertical yellow lines by sorting the data, so that is already done. Sorting the data is the solution to both problems.
tandemuse
tandemuse el 16 de Abr. de 2021
I found and ran a program that does what I'm trying to do. The result is the "desired result.png".
I changed the code a little bit to:
clear all
fs = 100;
data = load("P2-5.txt");
distance = 0.35;
% time = abs(data(1:1000,1));
% amplitude = data(1:1000,2);
time = data(:,1);
amplitude = data(:,2);
fstep = 2 : 0.5 : 46;
N = numel(fstep)-1;
central_freqs = NaN([1 N]);
filtered = NaN([numel(time) N]);
for i = 1:N
filtered(:,i) = bandpass(amplitude,[fstep(i) fstep(i+1)],fs);
filtered(:,i) = filtered(:,i)/max(abs(filtered(:,i)));
central_freqs(i) = 0.5*(fstep(i) + fstep(i+1));
end
central_periods = 1./central_freqs;
[Periods,Time] = meshgrid(central_periods,time);
surf(Periods,Time,filtered);
shading interp
view([0 90])
ylim([0 2])
xlim([min(central_periods) max(central_periods)])
% cb = colorbar;
% ylabel(cb,'Amplitude')
xlabel("Period (s)")
ylabel("time (s)")
title("Initial image")
% plot3(Freqs,Time,filtered)
% ylim([-1 0])
velocity = distance./(Time - 0.25.*Periods);
[velocity_sort, idx] = sort(velocity);
surf(Periods,velocity_sort,filtered(idx));
shading interp
ylim([0 6])
xlim([min(central_periods) max(central_periods)])
view([0 90])
% cb = colorbar;
% ylabel(cb,'Amplitude')
xlabel("Period (s)")
ylabel("phase velocity (km/s)")
title("Transformed image")
% plot3(Freqs,velocity,filtered)
% ylim([-10 0])
% xlim([2.5 15])
By not doing the sorting, I get the "attained result.png". Apart from the upper yellowish part, it shows a similar line going left to right from about 1.5 falling to 1km/s. This does resemble the "desired result.png"
By doing the sorting I get the "stars solution.png", which depicts a yellowish line starting just below 1km/s and slightly rising to 1km/s. This does not resemble so much the "desired result.png".
What I would like to do is to indeed make the image cleaner by removing the lines, but not to change the result, i.e. cleanup the "attained result.png".
If you feel like I should have rephrased the question, I can accept the answer and continue our discussion in another thread.
Star Strider
Star Strider el 16 de Abr. de 2021
It appears that ‘stars solution’ and ‘desired result’ are quite similar. The only difference is the orientation of the y-axis (one is the reverse of the other) and the colormap. I am not certain how ‘desired result’ was plotted (the plotting function), or how the ‘Period’ segments were calculated.
Of course, I would appreciate your accepting it, since I did a reasonable amount of work to get the result!
Note that this version of the plot:
figure
surf(Freqs,velocity_sorted,filtered(idx));
shading interp
ylim([-2 0])
xlim([min(central_freqs) 15])
view([0 90])
colormap(flipud(jet))
set(gca, 'YDir','reverse')
cb = colorbar;
ylabel(cb,'Amplitude')
xlabel("Frequency (Hz)")
ylabel("phase velocity (km/s)")
title("Transformed image")
looks quite similar to ‘desired resullt’:
The only changes I made here were the colormap (reversed jet) and reversing the direction of the y-axis, in order to more closely conform to the format of ‘desired result’. The calculations otherwise remain unchanged from my previous result. I am not certain how to make them completely compatible.
.
tandemuse
tandemuse el 17 de Abr. de 2021
Hey Star, just wanted to let you know that I've revised the calculations and the two cases are now essentially the same. Your solution is absolutely correct. Thank you very much!
Star Strider
Star Strider el 17 de Abr. de 2021
As always, my pleasure!
I very much appreciate your compliment, and for following up on this!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Preguntada:

el 15 de Abr. de 2021

Comentada:

el 17 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by