How can I subtract two WAV audio FFT signals?
11 views (last 30 days)
Show older comments
Avinash Kandalam
on 14 Jun 2021
Commented: Avinash Kandalam
on 13 Jul 2021
Hello MATLAB community,
Below, you will find 2 WAV files. One is the background noise and the other is the signal obtained during the experiment. I am interested in the 0-1000 Hz frequency range and as you can see in the below image, I figured out how to overlay 2 FFT's in 1 graph.
Now, I want to delete "noise FFT signal" from the "experimental FFT signal". Can I somehow subtract directly in the "Figure Window"? or I need to write an additional code?
In the example shown below, you can see a strong peak around 350 Hz, which I am looking at and by subtracting it from the background noise, I would get a smooth curve and obtain a raw experiment signal.
Finally, when I subtract 2 graphs, I could get just data points on the plot, which I want to join in a smooth line.
Thank you.
%clear, clc, close all
[y1,fs1]=audioread('Noise.wav');
t1=linspace(0,length(y1)/fs1,length(y1));
Nfft=8192;
% Nfft = length of fft
f1=linspace(0,fs1,Nfft);
X1=abs(fft(y1,Nfft));
%X = the fft of the samples y in 8192 points
plot(f1(1:Nfft/2),X1(1:Nfft/2))
xlim([0,1000])
%title('Combine Plots')
%2nd graph begins
hold on
[y2,fs2]=audioread('Experiment.wav');
t2=linspace(0,length(y1)/fs2,length(y1));
Nfft=8192;
% Nfft = length of fft
f2=linspace(0,fs2,Nfft);
X2=abs(fft(y2,Nfft));
%X = the fft of the samples y in 8192 points
plot(f2(1:Nfft/2),X2(1:Nfft/2))
xlabel('Frequency');
ylabel ('Amplitude');
title ('Background noise & experiment signals overlayed');
xlim([0,1000])
hold off
0 Comments
Accepted Answer
Kiran Felix Robert
on 13 Jul 2021
Hi Avinash,
You can easily use a one line script to subtract the curves.
The data points in the plot functions are
plot1_x = f1(1:Nfft/2);
plot1_y = X1(1:Nfft/2);
plot2_x = f2(1:Nfft/2);
plot2_y = X2(1:Nfft/2);
If f1 and f2 are of the same length, then you can perform the following operation to subtract,
difference = plot1_y - plot2_y;
You can plot using the following code,
plot(difference,plot1_x)
If the vectors are not of equal length, you can always pad zeros to the end of the smaller length signal.
More Answers (0)
See Also
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!