简体   繁体   中英

Smoothing 3D surface in Matlab

I am struggling with optimization of displayed 3D object. What I want to achieve is to make a 3D spectrogram of an audio file. What's more I want to have it black and white and nice looking. What does nice looking means - something like this: 在此处输入图片说明

This is just sample image - I am aware that spectrogram won't look like that

This is the code used for generating surface with reduced number of faces:

[y,fs,nbits]=wavread('audio.wav');
[s f t]= spectrogram(y(:,1),256,100,256,fs);
clear y
[X,Y]=meshgrid(t,f);
Z=log10(abs(s));

rskip = round(linspace(1,size(Z,1),80));
cskip = round(linspace(1,size(Z,2),64));
surf(X,Y,Z,'FaceColor','white','EdgeColor','none');
hold on
surf(X(rskip,:),Y(rskip,:),Z(rskip,:),'FaceColor','none','MeshStyle','row');
surf(X(:,cskip),Y(:,cskip),Z(:,cskip),'FaceColor','none','MeshStyle','column');
hold off
view(-65.5, 28);

The main problem with this audio file and reason why I am using reduced number of faces is the size of X,Y,Z arrays - all are 129 by 269065. My PC has 8GB of RAM and around 1GB is used by other applications (including OS) that is leaving around 6-7 GB for Matlab.

This is the image that is created after code run: 在此处输入图片说明

Can someone advice me how I can make it look smoother? Like the sample image.

If its purely for aesthetic reasons, a quick an dirty way to get a smoother image is to apply a gaussian filter to the power matrix returned from the spectrogram function.

clear;

[file,path] = uigetfile('*.wav');  % use GUI to select file
[y,fs,~] = wavread([path file]);

[p,f,t] = spectrogram(y(:,1),256,100,256,fs);
% Create the gaussian filter with hsize = [5 5] and sigma = 2
G = fspecial('gaussian',[5 5],2);
% Apply gaussian filter to the dB values
pBlur = imfilter(real(10*log10(p)),G,'same');

%# Show resulting spectograms (Filtered on top, origional on bottom)
figure(2);
imagesc([pBlur; real(10*log10(p))]);
colormap jet;

You can change the hsize and the sigma to adjust the blur properties.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM