# Plotting convoluted and original signals on the same graph

So I have a frequency response (got it by windowed fft-ing) of a note E4 played on a guitar and now I'm trying to implement a dynamic threshold for finding the peaks (fundamental frequency of the note and its harmonics).

I found an article that describes doing it by convolving normalized Hamming window with the frequency response. Now, I've done it, but I just don't know how to plot it correctly as the convoluted signal is delayed for a few samples like this (the red one): Here's the code in Scilab:

// plot the frequency response
x_axis = linspace(0, Fs, row);
plot(x_axis(1 : $/2), win_response); // calculate convolution on each window, siggram_n is just normalized // matrix of windowed freq. response [rows_sig, cols] = size(siggram_n); conv = []; for i = 1 : cols conv = [conv (convol(siggram_n(:, i), win_response))']; end // calculate the average of all convolutions [rows, cols] = size(ko); conv_n = []; for i = 1 : rows conv_n = [conv_n sum(conv(i, :))/cols]; end // raise to the power of 0.7 to flatten the threshold - from the article conv_n = conv_n .^ 0.7; // plot the convoluted signal x_axis = linspace(0, Fs, 2*length(conv_n)); plot(x_axis(1 :$/2), conv_n, 'red');


It's not only important that I know how to plot this, because I'll need to find the peaks, so I have to somehow "synchronize" both signals. What am I doing wrong?

Looks like you need to do a couple of things:

1. Use conv instead of convol
2. Change the order of the parameters of convol like this: conv( win_response,siggram_n(:, i))
3. Tell conv that it should return an array the same size as the first parameter conv( win_response,siggram_n(:, i),"same")

If you don't use "same" then you get a convolution result back that is the length of the first array plus twice the length of the second array. Convol has the parameters in the opposite order, and doesn't have a "same" option.

Also, change the name of your variable conv to something else. It is bad practice to use keywords as variable names. In this case, you have to change it else you can't use the conv method properly.

See the documentation for conv

• Wow, this totally solves it! I didn't even know there is another convolution function in Scilab, i.e. conv (also the reason for the variable name). I have to check the docs better next time. Thank you very much! – Luka Jun 29 '15 at 16:38