Audio signal Frequency Domain plotting symmetrical
Show older comments
I have an audio signal m4a thats converted to frequency domain using FFT. The plot I produced ranges from 0-48kHz. From what I understand, the 2 spectrums are not identical. So what I wish to do is to create a plot where the left spectrum is treated as the original values, and mirrored symmetricaly, with the nyquist frequency as the point of reference to mirror.


The left spectrum is what's gonna be controlled. the expected final plot ranges from 0-48kHz. I need to plot a symmetrically mirrored spectrum where if i were to shift the left spectrum to the right, the mirrored spectrum follows to the left, going closer to the nyquist frequenct point. Any values that crosses the nyquist frequency point will be ignored and not shown in the final plot.
1 Comment
Leonard Gay
on 6 Jun 2023
Moved: Star Strider
on 6 Jun 2023
Answers (1)
Hello!
As per my understanding, you want to produce a symmetrical frequency plot of your audio signal based on the left spectrum of the plot. This can be done as follows:
- Using the FFT, obtain the left spectrum of the audio signal.
- Calculate “N”, the length of the left spectrum.
- To store the mirrored spectrum, make a new array called “mirrored_spectrum” with the size of “nyquist_frequency”.
- In the first “N” items of “mirrored_spectrum”, copy the values from the “left_spectrum”.
- Use the “flip” function to fill in the mirrored values of the signal in the second half of “mirrored_spectrum”.
- Plot the mirrored spectrum.
Code Sample:
% Assuming you have the left spectrum stored in the variable 'left_spectrum'
% and the Nyquist frequency is 48 kHz
load gong.mat %Example file
sound(y)
left_spectrum=y;
N = length(left_spectrum);
nyquist_frequency = 48000; % Hz
mirrored_spectrum = zeros(nyquist_frequency,1); %The overall signal is in nyquist_frequency Hz.
mirrored_spectrum(1:N) = left_spectrum; %The starting values are the same as left spectrum.
mirrored_spectrum((nyquist_frequency/2)+1: end)=flip(mirrored_spectrum(1:(nyquist_frequency/2))); %The second half is the reverse of the first half.
plot(left_spectrum)
% Plotting the mirrored spectrum up to the Nyquist frequency
frequencies=(1:1:nyquist_frequency)';
plot(frequencies, mirrored_spectrum);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Mirrored Spectrum');
You may refer to the following documentation for more information about the “linspace” function: https://www.mathworks.com/help/matlab/ref/linspace.html
Hope this helps!
Categories
Find more on Audio I/O and Waveform Generation 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!
