################# #Created By: Gabriel LUCAS #Created :24/03/2023 08:27:54 # #Last modified: 02/03/2023 08:28:32 # # # # ################# pkg load signal; [y fs] = audioread("modulator22.wav"); t=[1:1:size(y,1)]; figure; plot(t,y) %xlabel('Time (s)'); %ylabel('Sound (dB)'); %Frequency spectrum using DFT [powerDFT durationDFT] = frequencySpectrum(y, fs, false); %Frequency spectrum using FFT [powerFFT durationFFT] = frequencySpectrum(y, fs, true); sprintf(["time used for DFT: " num2str(durationDFT)]) sprintf(["time used for FFT: " num2str(durationFFT)]) spectrogram(y, fs, 5, 30); spectrogram(y, fs, 5, 5); %spectrogram of "one" spectrogram(y(0.76*fs:0.96*fs), fs, 5, 30); %spectrogram of "two" spectrogram(y(1.38*fs:1.64*fs), fs, 5, 30); %spectrogram of "three" spectrogram(y(1.88*fs:2.18*fs), fs, 5, 30); %frequency spectrum for one n = length(y(0.76*fs:0.96*fs)); n = 2^nextpow2(n); t_one=[0:1/fs:(n-1)/fs]; signal = [ y(0.76*fs:0.96*fs); zeros( n-length(y(0.76*fs:0.96*fs)), 1)]; figure; plot(t_one, signal) xticks(0:0.1*fs:n*fs); xticklabels(0:0.1:n/fs); xlabel('Time (s)'); ylabel('Amplitude (a.u.)'); %frequency spectrum for two n = length(y(1.38*fs:1.64*fs)); n = 2^nextpow2(n); t_one=[0:1/fs:(n-1)/fs]; signal = [ y(1.38*fs:1.64*fs); zeros( n-length(y(1.38*fs:1.64*fs)), 1)]; figure; plot(t_one, signal) xticks(0:0.1*fs:n*fs); xticklabels(0:0.1:n/fs); xlabel('Time (s)'); ylabel('Amplitude (a.u.)'); %frequency spectrum for three n = length(y(1.88*fs:2.18*fs)); n = 2^nextpow2(n); t_one=[0:1/fs:(n-1)/fs]; signal = [ y(1.88*fs:2.18*fs); zeros( n-length(y(1.88*fs:2.18*fs)), 1)]; figure; plot(t_one, signal) xticks(0:0.1*fs:n*fs); xticklabels(0:0.1:n/fs); xlabel('Time (s)'); ylabel('Amplitude (a.u.)'); downsampled_signal = downsample(y, fs/4000); audiowrite("modulator_downsampled.wav", downsampled_signal, 4000); decimated_signal = decimate(y, 6); audiowrite("modulator_decimated.wav", decimated_signal, 4000); low_fir = fir1(30, 1/1000, 'low') freqz(low_fir); low_fir_signal = filter(low_fir, 1, y); audiowrite("low_fir_signal.wav", low_fir_signal, fs); [a, b] = butter(8, 1/1000, 'low') low_butter_signal = filter(a, b, y); audiowrite("low_butter_signal.wav", low_butter_signal, fs); low_fir_signal2 = downsample(low_fir_signal, fs/4000);