detect distortion in a sine signal using an undistorted one with Simulink

11 views (last 30 days)
Hello, could you give me an example on how to compare two sine signals with Simulink, one of them is a perfect sine and the other is the same but distorted? The purspose is to detect audio "glitches".
So far my thought is like this: create a two channel signal (1024*2) and save it as a .WAV file. Then import it to simulink. I wrote a Matlab function to create distortins to that file and save it as another file. then import the second one.
From here I am not really sure how to go forward. I would be thankful if you could tell me using simulink how to detect thses "glitches".
  2 Comments
Mathieu NOE
Mathieu NOE on 16 Feb 2023
hello
If both signals have same amplitude, you culd simply do the difference and this should let you detect the glitches
maybe if you would send the data we would better serve you
Walter Roberson
Walter Roberson on 16 Feb 2023
Edited: Walter Roberson on 16 Feb 2023
I thought I was getting somewhere, but it didn't work out. I thought looking at the RMS of the fft of the glitched and non-glitched signals would show a much higher difference for the glitched, but that does not turn out to be the case.
In the situation where you have two identical sine waves that are of different phase, and you have a sine wave of different phase that has noise in the middle of it, then it turns out that at least if the noise is not too large, that the phase differences can be a much larger influence.
If you look below at the zoomed fft of the pure sine waves (different phases) you can see notable differences near the peak of the fft. The root cause of this is that when the sample frequency is not a nice integer multiple of the sine wave frequency, then the peak energy is distributed between two adjacent bins -- and the mix of the two can depend upon the phase.
But also, when the number of samples is not a nice integer multiple of the sine frequency, then the fft assumption is violated that the input data is indefinitely repeatable, so mathematically the result is like convolving with a sinc signal, which is why the peak is not just an impulse.
A question here becomes whether when you say that the distorted one is "the same but distorted", do you mean that the distorted one is literally the same signal, same phase, same amplitude?
rng(12345)
Fs = 10000;
sinefreq = 234;
seconds = 1/5;
t = (0:seconds*Fs-1).' / Fs;
pure1 = sin(2 * pi * sinefreq * t + randn()*pi); %random phase
pure2 = sin(2 * pi * sinefreq * t + randn()*pi); %random phase
h = plot(t, [pure1, pure2]); title('pure sine'); legend({'#1', '#2'});
h(1).Marker = '.';
h(2).Marker = 'o';
distorted = sin(2 * pi * sinefreq * t + randn()*pi); %random phase
distorted(1000:1023) = rand();
plot(t, distorted); title('glitched sine');
Fp1 = fft(pure1 - mean(pure1));
Fp2 = fft(pure2 - mean(pure1));
Fd = fft(distorted - mean(distorted));
plot([real(Fp1), imag(Fp1)]);
hold on
plot([real(Fp2), imag(Fp2)], '--');
hold off
title('fft of pure'); legend({'real#1', 'imaginary#1', 'real#2', 'imaginary#2'});
plot([real(Fd), imag(Fd)]); title('fft of distorted'); legend({'real', 'imaginary'})
plot([real(Fp1(1:100)), imag(Fp1(1:100))], '-.');
hold on
plot([real(Fp2(1:100)), imag(Fp2(1:100))], '-o');
hold off
title('zoom fft of pure'); legend({'real#1', 'imaginary#1', 'real#2', 'imaginary#2'});
plot([real(Fd(1:100)), imag(Fd(1:100))]); title('zoom fft of distorted'); legend({'real', 'imaginary'})
difference_pure = real(Fp1) - real(Fp2);
differenced1 = real(Fp1) - real(Fd);
differenced2 = real(Fp2) - real(Fd);
measure_pure = rms(difference_pure)
measure_pure = 23.0592
measured1 = rms(differenced1)
measured1 = 22.4837
measured2 = rms(differenced2)
measured2 = 2.8165

Sign in to comment.

Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!