I currently have a spectrogram that is generated from an audio file and I am struggling to figure out how to get the surface data.
I would like to get the surface data of the spectrogram in order to convert it to an STL file using STLwrite or surf2STL. Is there anyway to get the X,Y,Z data from the spectrogram? Keep in mind, the X,Y,Z data would change when the program uses another audio file to generate another spectrogram. Any help is appreciated.
Here is the audio file used in the program. https://drive.google.com/file/d/1d__c9yvfezmhJakezxnVsj7OoDoXkFa_/view?usp=sharing
% 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,11,-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)
Best Answer