Recover signal from wav file using fft
Ältere Kommentare anzeigen
I am trying to use fft function in matlab to recover a signal from a music file Music.wav with lossy compression of CR=0.5 but not able to get it correctly.
Below is my Code
clc;
close all;
clear all;
%reading the given input Music.wav file using audioread()
y = audioread("Music.wav");
%Frame size
size = 2048;
%Creating final dct vectors
yt1 = [];
%looping the input vector frame by frame and getting all the three
%transfored frames from fft() and then taking inverse FFT to get
%the corresponding compressed data
for i=1:size:length(y)-size
yt_dct(:,1) = fft(y(i:i+size-1,1));
yt_dct(:,2) = fft(y(i:i+size-1,2));
yt1(i:i+size-1,1) = real(ifft(yt_dct(1:size/2,1),size));
yt1(i:i+size-1,2) = real(ifft(yt_dct(1:size/2,2),size));
end
%plotting the input file in time domain and in frequency domain
figure;
subplot(211);
plot(y);
title('Music.wav');
xlabel('time(s)');
ylabel('Amplitude');
grid on;
subplot(212);
plot((fft(y)));
title('Frequency spectrum of Music.wav');
xlabel('Frequency (KHz)');
ylabel('Amplitude');
xlim([-7.5,7.5]);
grid on;
%plotting all the music files and the input file in time domain
figure;
subplot(211);
plot(y);
title('Music.wav');
xlabel('time (s)');
ylabel('Amplitude');
grid on;
subplot(212);
plot(yt1);
title('music2.wav with CR = 0.5');
xlabel('time (s)');
ylabel('Amplitude');
grid on;
%plotting all the music files and the input file in Frequency domain
figure;
subplot(211);
plot(fft(y));
title('Frequency spectrum with Music.wav');
xlabel('Frequency (KHz)');
ylabel('Amplitude');
xlim([-7.5, 7.5]);
grid on;
subplot(212);
plot(fft(yt1));
title('Frequency spectrum of music2.wav with CR=0.5');
xlabel('Frequency (KHz)');
ylabel('Amplitude');
grid on;
xlim([-7.5, 7.5]);
%writing the output audio music files with the help of audiowrite
audiowrite('music2.wav',yt1);
The music2.wav file is also not that of expected
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Get Started with Signal Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!