Error using freqz, 6 columns needed to be a valid SOS matrix

23 views (last 30 days)
Hello, so in my code, i'm trying to apply digital filter over human speech, i'm using my friend voice by the way. However, when i'm trying to use freqz to plot the frequency domain of both the original and filter signal, the log says that my input must have 6 columns to be a valid SOS matrix. But, when i'm trying to use the sample audio from matlab (singing-a-major.ogg), the code works just perfectly. Here's the code i'm using:
%Generate Sound Wave
[x Fs] = audioread('D:\Bahan Wirus\test.mp3');
figure;
M = length(x);
subplot(321);
stem([0:M-1], x); grid on;
xlabel('index'); ylabel('amplitude');
title('Original Signal');
%FIR Filter
fc = 1000;
wc = 2*fc/Fs;
h = fir1(40, wc, hann(41));
y = filter(h,1,x);
subplot(322)
plot([0:M-1], y);grid on;
xlabel('index'); ylabel('amplitude');
title('Filterized signal');
[X,f] = freqz(x,1,1000,Fs);
subplot(323)
plot(f, 20*log10(abs(X)));grid on;
xlabel('frekuensi');
ylabel('Magnitudo (dB)');
title('Frequency domain of ori signal');
[Y,f] = freqz(y,1,1000,Fs);
subplot(324)
plot(f, 20*log10(abs(Y)));grid on;
xlabel('frekuensi');
ylabel('Magnitudo (dB)');
title('Frequency domain of filter signal');

Answers (2)

Chunru
Chunru on 23 May 2022
freqz is for filter response. use fft or pwelch (or other spectrum estimator) for ploting spectrum of signal.
%Generate Sound Wave
%[x Fs] = audioread('D:\Bahan Wirus\test.mp3');
% use random data instead
x = randn(100000, 1);
Fs = 22000;
figure;
M = length(x);
subplot(321);
stem([0:M-1], x); grid on;
xlabel('index'); ylabel('amplitude');
title('Original Signal');
%FIR Filter
fc = 1000;
wc = 2*fc/Fs;
h = fir1(40, wc, hann(41));
y = filter(h,1,x);
subplot(322)
plot([0:M-1], y);grid on;
xlabel('index'); ylabel('amplitude');
title('Filterized signal');
% For filter response, use filter coefficients instead of input signal
%[X,f] = freqz(x,1,1000,Fs);
[X,f] = freqz(h,1,8192,Fs);
subplot(323)
plot(f, 20*log10(abs(X)));grid on;
xlabel('frekuensi');
ylabel('Magnitudo (dB)');
title('Frequency Response of filter');
[Y, f] = pwelch(y, hamming(8192), 4096, Fs);
%[Y,f] = freqz(y,1,1000,Fs);
subplot(324)
plot(f, 20*log10(abs(Y)));grid on;
xlabel('frekuensi');
ylabel('Magnitudo (dB)');
title('Frequency domain of filter signal');

Walter Roberson
Walter Roberson on 23 May 2022
Your recording of your friend is probably stereo. Your code assumes mono.

Community Treasure Hunt

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

Start Hunting!