如何将 3D 频谱图转换为 STL 文件?

问题描述

我正在开发一个接受音频文件去除噪音、过滤声音并最终将其转换为可 3D 打印的 STL 文件的程序。我目前在我的程序中使用它接收音频文件,计算采样时间,删除音频数据的正确通道,绘制未过滤声音的时域和频域,过滤噪声,绘制时域和频域过滤后的声音,然后最终将其转换为 3d 频谱图。

我目前拥有看起来像 https://imgur.com/a/KX0wgxG 的 3D 频谱图。

我正在尝试实现 STLWrite 并生成“三角形”,但我不知道如何开始或做什么。

这是我当前的代码https://pastebin.com/KzR0kRJc

%import Matlab's Hallelujah sound file
% load handel
% filename = 'Halleluja.wav';
% audiowrite(filename,y,Fs);
% clear y Fs;
% [sample_data,sample_rate] = audioread(filename);

%uncomment out the next two lines if you want to import your own sound file
filename = 'Halleluja.wav'
[sample_data,sample_rate] = audioread(filename');

info = audioinfo(filename)

%listen to unfiltered sound file
sound(sample_data,sample_rate)

%stop sound
clear sound

%calculate the sampling times
sample_period = 1/sample_rate;                              %calculate the time between samples
%samples = [1,2*sample_rate];                                %modify number of samples
%[sample_data,sample_rate] = audioread(filename,samples);   %re-import sound file using modified rate

%remove the right channel of audio data
sample_data_width = size(sample_data);
if(sample_data_width(2) == 2)
    sample_data(:,1) = [];  
end

%Generate the sampling times
time = 0:sample_period:(length(sample_data)-1)/sample_rate;

%Plot the Time Domain Representation of Unfiltered Sound
plot(time,sample_data)
height_multiplier = 1.6;
axis([0,11,-1/height_multiplier,1/height_multiplier])
title('Time Domain Representation - Unfiltered Sound')
xlabel('Time (seconds)')
ylabel('Amplitude')
xlim([0 time(end)])

%Plot the Frequency Domain Representation of Unfiltered Sound
m = length(sample_data);                                    %Calculate the original sample length
n = pow2(nextpow2(m));                                      %Transform the length so the number of samples is a power of 2
y = fft(sample_data,n);                                    %Calculate the Fast Fourier Transform
frequencies = (0:n-1)*(sample_rate/n);                      %Generate the frequencies 
amplitudes = abs(y)/n;                                      %Generate the amplitudes

%Plot the Frequency Domain
plot(frequencies(1:floor(n/2)),amplitudes(1:floor(n/2)))
title('Frequency Domain Representation - Unfiltered Sound')
xlabel('Frequency')
ylabel('Amplitude')
width_slider2 = 1;
xlim([0 frequencies(end)/width_slider2])


%Filtered Sound

%Filter out the noise
order = 7;
[b,a] = butter(order,1000/(sample_rate/2),'low');
filtered_sound = filter(b,a,sample_data);

sound(filtered_sound,sample_rate)                          %Listen the unfiltered sound file

clear sound                                                 %stop sound

%Plot the Time Domain Representation - Filtered Sound 

%Generate the new sampling times
time2 = (0:sample_period:(length(filtered_sound)-1)/sample_rate);

%Plot the Time Domain Representation
plot(time2,filtered_sound)
height_multiplier2 = 1;
axis([0,-1/height_multiplier2,1/height_multiplier2])
title('Time Domain Representation - Filtered Sound')
xlabel('Time (seconds)')
ylabel('Amplitude')
xlim([0 time2(end)])


%Plot the Frequency Domain Representation - Filtered Sound 
m1 = length(sample_data);                                   % Calculate the original sample length
n1 = pow2(nextpow2(m1));                                    % Transform the length so the number of sampels is a power of 2.
y1 = fft(filtered_sound,n1);                               % Calculate the Fast Fourier Transform  
frequencies2 = (0:n1-1)*(sample_rate/n1);                   % Generate the frequencies
amplitudes2 = abs(y1)/n1;                                   % Generate the amplitudes

%Plot the Frequency Domain Representation
plot(frequencies2(1:floor(n1/2)),amplitudes2(1:floor(n1/2)))
title('Frequency Domain Representation - Filtered Sound')
xlabel('Frequency')
ylabel('Amplitude')
width_slider2 = 11;
xlim([0 frequencies2(end)/width_slider2])

%3D Spectrogram - Filtered Sound
win = 128;                                                  % Window length in samples                                                          
hop = win/2;                                                % Number of samples between overlapping windows
nfft = win;                                                 % Width of each frequency bin
spectrogram(filtered_sound,win,hop,nfft,sample_rate,'yaxis');
view(-45,65)

这是程序中使用的音频文件https://drive.google.com/file/d/1d__c9yvfezmhJakezxnVsj7OoDoXkFa_/view?usp=sharing

任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)