[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #63440] [octave forge] (signal) sosfilt - NaN
From: |
Charles Praplan |
Subject: |
[Octave-bug-tracker] [bug #63440] [octave forge] (signal) sosfilt - NaN |
Date: |
Wed, 11 Jan 2023 12:14:52 -0500 (EST) |
Follow-up Comment #11, bug #63440 (project octave):
Hi Renato,
Unfortunately the function you want is not written. So you have to manage
without it.
Independently of this function, just run the following code to plot the
spectrum
before and after your while loop.
Although the while loop does its job of changing the crest factor, you will
see that is
adding some LF (white) noise to your signal.
close all
clear
clc
pkg load ltfat
sampling_rate = 44100;
length_fact = 30;
hpf = 40;
lpf = 400;
crest_factor = 6;
filter_order = 4;
rounding = 4;
typenoise = noise((length_fact/2)*sampling_rate, 1, 'pink');
%load typenoise.mat
[z, p, k] = butter(filter_order, [hpf/(sampling_rate/2),
lpf/(sampling_rate/2)]);
sos = zp2sos (z, p, k);
filtered = sosfilt(sos, typenoise);
normalized = filtered / (rms(filtered) / 10^(-crest_factor/20));
normalized_before_while_loop=normalized;
while crestfactor(normalized) > crest_factor
normalized(normalized > 0) = ((normalized(normalized > 0).^rounding) ./
((normalized(normalized > 0).^rounding) + 1)).^(1/rounding);
normalized(normalized < 0) = (((normalized(normalized < 0).^rounding) ./
((normalized(normalized < 0).^rounding) + 1)).^(1/rounding)) *-1;
rounding = rounding^2;
if rounding > 100
rounding = 100;
end
normalized = normalized / (rms(normalized) / 10^(-crest_factor/20));
end;
second_half = normalized * -1;
normalized = [[normalized]; [second_half]];
hist(normalized, 61);
xlabel('Amplitude');
ylabel('Samples');
grid on;
[spectra,freq] =
pwelch(normalized_before_while_loop,hann(length(normalized_before_while_loop)),0,length(normalized_before_while_loop),sampling_rate);
figure
loglog(freq,spectra)
[spectra,freq] =
pwelch(normalized,hann(length(normalized)),0,length(normalized),sampling_rate);
hold on
loglog(freq,spectra)
grid on
legend('spectrum before while loop', 'spectrum after while loop')
xlabel('[Hz]')
ylabel('Amplitude')
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?63440>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/