2015-07-21 196 views
0

我正在努力優化顯示的3D對象。我想要實現的是製作音頻文件的3D頻譜圖。還有什麼我想要它黑色和白色,漂亮的外觀。什麼好看的手段 - 是這樣的: enter image description here在Matlab中平滑3D曲面

這只是樣本圖像 - 我知道,頻譜不會像那個

這是用於與數量減少的表面生成的代碼的面孔。

[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); 

與此音頻文件和原因,我使用減少面數的主要問題是X,Y,Z數組的大小 - 都是由129我269065. PC擁有8GB的內存其他應用程序使用大約1GB(包括1GB) uding操作系統),離開大約6-7GB的Matlab。

這是代碼運行後創建的圖像: enter image description here

有人能指點我如何使它看起來更順暢?像示例圖像一樣。

+0

您是否想過嘗試2D移動平均值?或者你可以看看這個http://stackoverflow.com/questions/29864618/how-can-i-smooth-a-surface-in-matlab?rq=1 – willpower2727

回答

0

如果純粹出於美學原因,快速骯髒的方法來獲得更平滑的圖像是應用高斯濾波器從譜圖函數返回的功率矩陣。

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; 

您可以更改hsizesigma調整模糊性。

enter image description here